ホーム › Security.Cryptography › CryptImportPublicKeyInfo
CryptImportPublicKeyInfo
関数公開鍵情報をインポートして鍵ハンドルを取得する。
シグネチャ
// CRYPT32.dll
#include <windows.h>
BOOL CryptImportPublicKeyInfo(
UINT_PTR hCryptProv,
CERT_QUERY_ENCODING_TYPE dwCertEncodingType,
CERT_PUBLIC_KEY_INFO* pInfo,
UINT_PTR* phKey
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hCryptProv | UINT_PTR | in |
| dwCertEncodingType | CERT_QUERY_ENCODING_TYPE | in |
| pInfo | CERT_PUBLIC_KEY_INFO* | in |
| phKey | UINT_PTR* | out |
戻り値の型: BOOL
各言語での呼び出し定義
// CRYPT32.dll
#include <windows.h>
BOOL CryptImportPublicKeyInfo(
UINT_PTR hCryptProv,
CERT_QUERY_ENCODING_TYPE dwCertEncodingType,
CERT_PUBLIC_KEY_INFO* pInfo,
UINT_PTR* phKey
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CryptImportPublicKeyInfo(
UIntPtr hCryptProv, // UINT_PTR
uint dwCertEncodingType, // CERT_QUERY_ENCODING_TYPE
IntPtr pInfo, // CERT_PUBLIC_KEY_INFO*
out UIntPtr phKey // UINT_PTR* out
);<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CryptImportPublicKeyInfo(
hCryptProv As UIntPtr, ' UINT_PTR
dwCertEncodingType As UInteger, ' CERT_QUERY_ENCODING_TYPE
pInfo As IntPtr, ' CERT_PUBLIC_KEY_INFO*
<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*
' phKey : UINT_PTR* out
Declare PtrSafe Function CryptImportPublicKeyInfo Lib "crypt32" ( _
ByVal hCryptProv As LongPtr, _
ByVal dwCertEncodingType As Long, _
ByVal pInfo 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
CryptImportPublicKeyInfo = ctypes.windll.crypt32.CryptImportPublicKeyInfo
CryptImportPublicKeyInfo.restype = wintypes.BOOL
CryptImportPublicKeyInfo.argtypes = [
ctypes.c_size_t, # hCryptProv : UINT_PTR
wintypes.DWORD, # dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
ctypes.c_void_p, # pInfo : CERT_PUBLIC_KEY_INFO*
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')
CryptImportPublicKeyInfo = Fiddle::Function.new(
lib['CryptImportPublicKeyInfo'],
[
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_VOIDP, # phKey : UINT_PTR* out
],
Fiddle::TYPE_INT)#[link(name = "crypt32")]
extern "system" {
fn CryptImportPublicKeyInfo(
hCryptProv: usize, // UINT_PTR
dwCertEncodingType: u32, // CERT_QUERY_ENCODING_TYPE
pInfo: *mut CERT_PUBLIC_KEY_INFO, // CERT_PUBLIC_KEY_INFO*
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 CryptImportPublicKeyInfo(UIntPtr hCryptProv, uint dwCertEncodingType, IntPtr pInfo, out UIntPtr phKey);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CryptImportPublicKeyInfo' -Namespace Win32 -PassThru
# $api::CryptImportPublicKeyInfo(hCryptProv, dwCertEncodingType, pInfo, phKey)#uselib "CRYPT32.dll"
#func global CryptImportPublicKeyInfo "CryptImportPublicKeyInfo" sptr, sptr, sptr, sptr
; CryptImportPublicKeyInfo hCryptProv, dwCertEncodingType, varptr(pInfo), varptr(phKey) ; 戻り値は stat
; hCryptProv : UINT_PTR -> "sptr"
; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "sptr"
; pInfo : CERT_PUBLIC_KEY_INFO* -> "sptr"
; phKey : UINT_PTR* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "CRYPT32.dll" #cfunc global CryptImportPublicKeyInfo "CryptImportPublicKeyInfo" sptr, int, var, var ; res = CryptImportPublicKeyInfo(hCryptProv, dwCertEncodingType, pInfo, phKey) ; hCryptProv : UINT_PTR -> "sptr" ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; pInfo : CERT_PUBLIC_KEY_INFO* -> "var" ; phKey : UINT_PTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "CRYPT32.dll" #cfunc global CryptImportPublicKeyInfo "CryptImportPublicKeyInfo" sptr, int, sptr, sptr ; res = CryptImportPublicKeyInfo(hCryptProv, dwCertEncodingType, varptr(pInfo), varptr(phKey)) ; hCryptProv : UINT_PTR -> "sptr" ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; pInfo : CERT_PUBLIC_KEY_INFO* -> "sptr" ; phKey : UINT_PTR* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL CryptImportPublicKeyInfo(UINT_PTR hCryptProv, CERT_QUERY_ENCODING_TYPE dwCertEncodingType, CERT_PUBLIC_KEY_INFO* pInfo, UINT_PTR* phKey) #uselib "CRYPT32.dll" #cfunc global CryptImportPublicKeyInfo "CryptImportPublicKeyInfo" intptr, int, var, var ; res = CryptImportPublicKeyInfo(hCryptProv, dwCertEncodingType, pInfo, phKey) ; hCryptProv : UINT_PTR -> "intptr" ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; pInfo : CERT_PUBLIC_KEY_INFO* -> "var" ; phKey : UINT_PTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL CryptImportPublicKeyInfo(UINT_PTR hCryptProv, CERT_QUERY_ENCODING_TYPE dwCertEncodingType, CERT_PUBLIC_KEY_INFO* pInfo, UINT_PTR* phKey) #uselib "CRYPT32.dll" #cfunc global CryptImportPublicKeyInfo "CryptImportPublicKeyInfo" intptr, int, intptr, intptr ; res = CryptImportPublicKeyInfo(hCryptProv, dwCertEncodingType, varptr(pInfo), varptr(phKey)) ; hCryptProv : UINT_PTR -> "intptr" ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; pInfo : CERT_PUBLIC_KEY_INFO* -> "intptr" ; phKey : UINT_PTR* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
procCryptImportPublicKeyInfo = crypt32.NewProc("CryptImportPublicKeyInfo")
)
// hCryptProv (UINT_PTR), dwCertEncodingType (CERT_QUERY_ENCODING_TYPE), pInfo (CERT_PUBLIC_KEY_INFO*), phKey (UINT_PTR* out)
r1, _, err := procCryptImportPublicKeyInfo.Call(
uintptr(hCryptProv),
uintptr(dwCertEncodingType),
uintptr(pInfo),
uintptr(phKey),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CryptImportPublicKeyInfo(
hCryptProv: NativeUInt; // UINT_PTR
dwCertEncodingType: DWORD; // CERT_QUERY_ENCODING_TYPE
pInfo: Pointer; // CERT_PUBLIC_KEY_INFO*
phKey: Pointer // UINT_PTR* out
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CryptImportPublicKeyInfo';result := DllCall("CRYPT32\CryptImportPublicKeyInfo"
, "UPtr", hCryptProv ; UINT_PTR
, "UInt", dwCertEncodingType ; CERT_QUERY_ENCODING_TYPE
, "Ptr", pInfo ; CERT_PUBLIC_KEY_INFO*
, "Ptr", phKey ; UINT_PTR* out
, "Int") ; return: BOOL●CryptImportPublicKeyInfo(hCryptProv, dwCertEncodingType, pInfo, phKey) = DLL("CRYPT32.dll", "bool CryptImportPublicKeyInfo(int, dword, void*, void*)")
# 呼び出し: CryptImportPublicKeyInfo(hCryptProv, dwCertEncodingType, pInfo, phKey)
# hCryptProv : UINT_PTR -> "int"
# dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "dword"
# pInfo : CERT_PUBLIC_KEY_INFO* -> "void*"
# phKey : UINT_PTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。