ホーム › Security.Cryptography › CryptImportPublicKeyInfoEx
CryptImportPublicKeyInfoEx
関数鍵アルゴリズムを指定して公開鍵情報を拡張インポートする。
シグネチャ
// CRYPT32.dll
#include <windows.h>
BOOL CryptImportPublicKeyInfoEx(
UINT_PTR hCryptProv,
CERT_QUERY_ENCODING_TYPE dwCertEncodingType,
CERT_PUBLIC_KEY_INFO* pInfo,
ALG_ID aiKeyAlg,
DWORD dwFlags,
void* pvAuxInfo, // optional
UINT_PTR* phKey
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hCryptProv | UINT_PTR | in |
| dwCertEncodingType | CERT_QUERY_ENCODING_TYPE | in |
| pInfo | CERT_PUBLIC_KEY_INFO* | in |
| aiKeyAlg | ALG_ID | in |
| dwFlags | DWORD | in |
| pvAuxInfo | void* | inoptional |
| phKey | UINT_PTR* | out |
戻り値の型: BOOL
各言語での呼び出し定義
// CRYPT32.dll
#include <windows.h>
BOOL CryptImportPublicKeyInfoEx(
UINT_PTR hCryptProv,
CERT_QUERY_ENCODING_TYPE dwCertEncodingType,
CERT_PUBLIC_KEY_INFO* pInfo,
ALG_ID aiKeyAlg,
DWORD dwFlags,
void* pvAuxInfo, // optional
UINT_PTR* phKey
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CryptImportPublicKeyInfoEx(
UIntPtr hCryptProv, // UINT_PTR
uint dwCertEncodingType, // CERT_QUERY_ENCODING_TYPE
IntPtr pInfo, // CERT_PUBLIC_KEY_INFO*
uint aiKeyAlg, // ALG_ID
uint dwFlags, // DWORD
IntPtr pvAuxInfo, // void* optional
out UIntPtr phKey // UINT_PTR* out
);<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CryptImportPublicKeyInfoEx(
hCryptProv As UIntPtr, ' UINT_PTR
dwCertEncodingType As UInteger, ' CERT_QUERY_ENCODING_TYPE
pInfo As IntPtr, ' CERT_PUBLIC_KEY_INFO*
aiKeyAlg As UInteger, ' ALG_ID
dwFlags As UInteger, ' DWORD
pvAuxInfo As IntPtr, ' void* optional
<Out> ByRef phKey As UIntPtr ' UINT_PTR* out
) As Boolean
End Function' hCryptProv : UINT_PTR
' dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
' pInfo : CERT_PUBLIC_KEY_INFO*
' aiKeyAlg : ALG_ID
' dwFlags : DWORD
' pvAuxInfo : void* optional
' phKey : UINT_PTR* out
Declare PtrSafe Function CryptImportPublicKeyInfoEx Lib "crypt32" ( _
ByVal hCryptProv As LongPtr, _
ByVal dwCertEncodingType As Long, _
ByVal pInfo As LongPtr, _
ByVal aiKeyAlg As Long, _
ByVal dwFlags As Long, _
ByVal pvAuxInfo As LongPtr, _
ByRef phKey As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CryptImportPublicKeyInfoEx = ctypes.windll.crypt32.CryptImportPublicKeyInfoEx
CryptImportPublicKeyInfoEx.restype = wintypes.BOOL
CryptImportPublicKeyInfoEx.argtypes = [
ctypes.c_size_t, # hCryptProv : UINT_PTR
wintypes.DWORD, # dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
ctypes.c_void_p, # pInfo : CERT_PUBLIC_KEY_INFO*
wintypes.DWORD, # aiKeyAlg : ALG_ID
wintypes.DWORD, # dwFlags : DWORD
ctypes.POINTER(None), # pvAuxInfo : void* optional
ctypes.POINTER(ctypes.c_size_t), # phKey : UINT_PTR* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('CRYPT32.dll')
CryptImportPublicKeyInfoEx = Fiddle::Function.new(
lib['CryptImportPublicKeyInfoEx'],
[
Fiddle::TYPE_UINTPTR_T, # hCryptProv : UINT_PTR
-Fiddle::TYPE_INT, # dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
Fiddle::TYPE_VOIDP, # pInfo : CERT_PUBLIC_KEY_INFO*
-Fiddle::TYPE_INT, # aiKeyAlg : ALG_ID
-Fiddle::TYPE_INT, # dwFlags : DWORD
Fiddle::TYPE_VOIDP, # pvAuxInfo : void* optional
Fiddle::TYPE_VOIDP, # phKey : UINT_PTR* out
],
Fiddle::TYPE_INT)#[link(name = "crypt32")]
extern "system" {
fn CryptImportPublicKeyInfoEx(
hCryptProv: usize, // UINT_PTR
dwCertEncodingType: u32, // CERT_QUERY_ENCODING_TYPE
pInfo: *mut CERT_PUBLIC_KEY_INFO, // CERT_PUBLIC_KEY_INFO*
aiKeyAlg: u32, // ALG_ID
dwFlags: u32, // DWORD
pvAuxInfo: *mut (), // void* optional
phKey: *mut usize // UINT_PTR* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true)]
public static extern bool CryptImportPublicKeyInfoEx(UIntPtr hCryptProv, uint dwCertEncodingType, IntPtr pInfo, uint aiKeyAlg, uint dwFlags, IntPtr pvAuxInfo, out UIntPtr phKey);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CryptImportPublicKeyInfoEx' -Namespace Win32 -PassThru
# $api::CryptImportPublicKeyInfoEx(hCryptProv, dwCertEncodingType, pInfo, aiKeyAlg, dwFlags, pvAuxInfo, phKey)#uselib "CRYPT32.dll"
#func global CryptImportPublicKeyInfoEx "CryptImportPublicKeyInfoEx" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; CryptImportPublicKeyInfoEx hCryptProv, dwCertEncodingType, varptr(pInfo), aiKeyAlg, dwFlags, pvAuxInfo, varptr(phKey) ; 戻り値は stat
; hCryptProv : UINT_PTR -> "sptr"
; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "sptr"
; pInfo : CERT_PUBLIC_KEY_INFO* -> "sptr"
; aiKeyAlg : ALG_ID -> "sptr"
; dwFlags : DWORD -> "sptr"
; pvAuxInfo : void* optional -> "sptr"
; phKey : UINT_PTR* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "CRYPT32.dll" #cfunc global CryptImportPublicKeyInfoEx "CryptImportPublicKeyInfoEx" sptr, int, var, int, int, sptr, var ; res = CryptImportPublicKeyInfoEx(hCryptProv, dwCertEncodingType, pInfo, aiKeyAlg, dwFlags, pvAuxInfo, phKey) ; hCryptProv : UINT_PTR -> "sptr" ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; pInfo : CERT_PUBLIC_KEY_INFO* -> "var" ; aiKeyAlg : ALG_ID -> "int" ; dwFlags : DWORD -> "int" ; pvAuxInfo : void* optional -> "sptr" ; phKey : UINT_PTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "CRYPT32.dll" #cfunc global CryptImportPublicKeyInfoEx "CryptImportPublicKeyInfoEx" sptr, int, sptr, int, int, sptr, sptr ; res = CryptImportPublicKeyInfoEx(hCryptProv, dwCertEncodingType, varptr(pInfo), aiKeyAlg, dwFlags, pvAuxInfo, varptr(phKey)) ; hCryptProv : UINT_PTR -> "sptr" ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; pInfo : CERT_PUBLIC_KEY_INFO* -> "sptr" ; aiKeyAlg : ALG_ID -> "int" ; dwFlags : DWORD -> "int" ; pvAuxInfo : void* optional -> "sptr" ; phKey : UINT_PTR* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL CryptImportPublicKeyInfoEx(UINT_PTR hCryptProv, CERT_QUERY_ENCODING_TYPE dwCertEncodingType, CERT_PUBLIC_KEY_INFO* pInfo, ALG_ID aiKeyAlg, DWORD dwFlags, void* pvAuxInfo, UINT_PTR* phKey) #uselib "CRYPT32.dll" #cfunc global CryptImportPublicKeyInfoEx "CryptImportPublicKeyInfoEx" intptr, int, var, int, int, intptr, var ; res = CryptImportPublicKeyInfoEx(hCryptProv, dwCertEncodingType, pInfo, aiKeyAlg, dwFlags, pvAuxInfo, phKey) ; hCryptProv : UINT_PTR -> "intptr" ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; pInfo : CERT_PUBLIC_KEY_INFO* -> "var" ; aiKeyAlg : ALG_ID -> "int" ; dwFlags : DWORD -> "int" ; pvAuxInfo : void* optional -> "intptr" ; phKey : UINT_PTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL CryptImportPublicKeyInfoEx(UINT_PTR hCryptProv, CERT_QUERY_ENCODING_TYPE dwCertEncodingType, CERT_PUBLIC_KEY_INFO* pInfo, ALG_ID aiKeyAlg, DWORD dwFlags, void* pvAuxInfo, UINT_PTR* phKey) #uselib "CRYPT32.dll" #cfunc global CryptImportPublicKeyInfoEx "CryptImportPublicKeyInfoEx" intptr, int, intptr, int, int, intptr, intptr ; res = CryptImportPublicKeyInfoEx(hCryptProv, dwCertEncodingType, varptr(pInfo), aiKeyAlg, dwFlags, pvAuxInfo, varptr(phKey)) ; hCryptProv : UINT_PTR -> "intptr" ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; pInfo : CERT_PUBLIC_KEY_INFO* -> "intptr" ; aiKeyAlg : ALG_ID -> "int" ; dwFlags : DWORD -> "int" ; pvAuxInfo : void* optional -> "intptr" ; phKey : UINT_PTR* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
procCryptImportPublicKeyInfoEx = crypt32.NewProc("CryptImportPublicKeyInfoEx")
)
// hCryptProv (UINT_PTR), dwCertEncodingType (CERT_QUERY_ENCODING_TYPE), pInfo (CERT_PUBLIC_KEY_INFO*), aiKeyAlg (ALG_ID), dwFlags (DWORD), pvAuxInfo (void* optional), phKey (UINT_PTR* out)
r1, _, err := procCryptImportPublicKeyInfoEx.Call(
uintptr(hCryptProv),
uintptr(dwCertEncodingType),
uintptr(pInfo),
uintptr(aiKeyAlg),
uintptr(dwFlags),
uintptr(pvAuxInfo),
uintptr(phKey),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CryptImportPublicKeyInfoEx(
hCryptProv: NativeUInt; // UINT_PTR
dwCertEncodingType: DWORD; // CERT_QUERY_ENCODING_TYPE
pInfo: Pointer; // CERT_PUBLIC_KEY_INFO*
aiKeyAlg: DWORD; // ALG_ID
dwFlags: DWORD; // DWORD
pvAuxInfo: Pointer; // void* optional
phKey: Pointer // UINT_PTR* out
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CryptImportPublicKeyInfoEx';result := DllCall("CRYPT32\CryptImportPublicKeyInfoEx"
, "UPtr", hCryptProv ; UINT_PTR
, "UInt", dwCertEncodingType ; CERT_QUERY_ENCODING_TYPE
, "Ptr", pInfo ; CERT_PUBLIC_KEY_INFO*
, "UInt", aiKeyAlg ; ALG_ID
, "UInt", dwFlags ; DWORD
, "Ptr", pvAuxInfo ; void* optional
, "Ptr", phKey ; UINT_PTR* out
, "Int") ; return: BOOL●CryptImportPublicKeyInfoEx(hCryptProv, dwCertEncodingType, pInfo, aiKeyAlg, dwFlags, pvAuxInfo, phKey) = DLL("CRYPT32.dll", "bool CryptImportPublicKeyInfoEx(int, dword, void*, dword, dword, void*, void*)")
# 呼び出し: CryptImportPublicKeyInfoEx(hCryptProv, dwCertEncodingType, pInfo, aiKeyAlg, dwFlags, pvAuxInfo, phKey)
# hCryptProv : UINT_PTR -> "int"
# dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "dword"
# pInfo : CERT_PUBLIC_KEY_INFO* -> "void*"
# aiKeyAlg : ALG_ID -> "dword"
# dwFlags : DWORD -> "dword"
# pvAuxInfo : void* optional -> "void*"
# phKey : UINT_PTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。