Win32 API 日本語リファレンス
ホームSecurity.Cryptography › CryptFindCertificateKeyProvInfo

CryptFindCertificateKeyProvInfo

関数
証明書に対応する鍵プロバイダ情報を検索し設定する。
DLLCRYPT32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// CRYPT32.dll
#include <windows.h>

BOOL CryptFindCertificateKeyProvInfo(
    const CERT_CONTEXT* pCert,
    CRYPT_FIND_FLAGS dwFlags,
    void* pvReserved   // optional
);

パラメーター

名前方向
pCertCERT_CONTEXT*in
dwFlagsCRYPT_FIND_FLAGSin
pvReservedvoid*optional

戻り値の型: BOOL

各言語での呼び出し定義

// CRYPT32.dll
#include <windows.h>

BOOL CryptFindCertificateKeyProvInfo(
    const CERT_CONTEXT* pCert,
    CRYPT_FIND_FLAGS dwFlags,
    void* pvReserved   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CryptFindCertificateKeyProvInfo(
    IntPtr pCert,   // CERT_CONTEXT*
    uint dwFlags,   // CRYPT_FIND_FLAGS
    IntPtr pvReserved   // void* optional
);
<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CryptFindCertificateKeyProvInfo(
    pCert As IntPtr,   ' CERT_CONTEXT*
    dwFlags As UInteger,   ' CRYPT_FIND_FLAGS
    pvReserved As IntPtr   ' void* optional
) As Boolean
End Function
' pCert : CERT_CONTEXT*
' dwFlags : CRYPT_FIND_FLAGS
' pvReserved : void* optional
Declare PtrSafe Function CryptFindCertificateKeyProvInfo Lib "crypt32" ( _
    ByVal pCert As LongPtr, _
    ByVal dwFlags As Long, _
    ByVal pvReserved As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CryptFindCertificateKeyProvInfo = ctypes.windll.crypt32.CryptFindCertificateKeyProvInfo
CryptFindCertificateKeyProvInfo.restype = wintypes.BOOL
CryptFindCertificateKeyProvInfo.argtypes = [
    ctypes.c_void_p,  # pCert : CERT_CONTEXT*
    wintypes.DWORD,  # dwFlags : CRYPT_FIND_FLAGS
    ctypes.POINTER(None),  # pvReserved : void* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('CRYPT32.dll')
CryptFindCertificateKeyProvInfo = Fiddle::Function.new(
  lib['CryptFindCertificateKeyProvInfo'],
  [
    Fiddle::TYPE_VOIDP,  # pCert : CERT_CONTEXT*
    -Fiddle::TYPE_INT,  # dwFlags : CRYPT_FIND_FLAGS
    Fiddle::TYPE_VOIDP,  # pvReserved : void* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "crypt32")]
extern "system" {
    fn CryptFindCertificateKeyProvInfo(
        pCert: *const CERT_CONTEXT,  // CERT_CONTEXT*
        dwFlags: u32,  // CRYPT_FIND_FLAGS
        pvReserved: *mut ()  // void* optional
    ) -> 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 CryptFindCertificateKeyProvInfo(IntPtr pCert, uint dwFlags, IntPtr pvReserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CryptFindCertificateKeyProvInfo' -Namespace Win32 -PassThru
# $api::CryptFindCertificateKeyProvInfo(pCert, dwFlags, pvReserved)
#uselib "CRYPT32.dll"
#func global CryptFindCertificateKeyProvInfo "CryptFindCertificateKeyProvInfo" sptr, sptr, sptr
; CryptFindCertificateKeyProvInfo varptr(pCert), dwFlags, pvReserved   ; 戻り値は stat
; pCert : CERT_CONTEXT* -> "sptr"
; dwFlags : CRYPT_FIND_FLAGS -> "sptr"
; pvReserved : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "CRYPT32.dll"
#cfunc global CryptFindCertificateKeyProvInfo "CryptFindCertificateKeyProvInfo" var, int, sptr
; res = CryptFindCertificateKeyProvInfo(pCert, dwFlags, pvReserved)
; pCert : CERT_CONTEXT* -> "var"
; dwFlags : CRYPT_FIND_FLAGS -> "int"
; pvReserved : void* optional -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL CryptFindCertificateKeyProvInfo(CERT_CONTEXT* pCert, CRYPT_FIND_FLAGS dwFlags, void* pvReserved)
#uselib "CRYPT32.dll"
#cfunc global CryptFindCertificateKeyProvInfo "CryptFindCertificateKeyProvInfo" var, int, intptr
; res = CryptFindCertificateKeyProvInfo(pCert, dwFlags, pvReserved)
; pCert : CERT_CONTEXT* -> "var"
; dwFlags : CRYPT_FIND_FLAGS -> "int"
; pvReserved : void* optional -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
	procCryptFindCertificateKeyProvInfo = crypt32.NewProc("CryptFindCertificateKeyProvInfo")
)

// pCert (CERT_CONTEXT*), dwFlags (CRYPT_FIND_FLAGS), pvReserved (void* optional)
r1, _, err := procCryptFindCertificateKeyProvInfo.Call(
	uintptr(pCert),
	uintptr(dwFlags),
	uintptr(pvReserved),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function CryptFindCertificateKeyProvInfo(
  pCert: Pointer;   // CERT_CONTEXT*
  dwFlags: DWORD;   // CRYPT_FIND_FLAGS
  pvReserved: Pointer   // void* optional
): BOOL; stdcall;
  external 'CRYPT32.dll' name 'CryptFindCertificateKeyProvInfo';
result := DllCall("CRYPT32\CryptFindCertificateKeyProvInfo"
    , "Ptr", pCert   ; CERT_CONTEXT*
    , "UInt", dwFlags   ; CRYPT_FIND_FLAGS
    , "Ptr", pvReserved   ; void* optional
    , "Int")   ; return: BOOL
●CryptFindCertificateKeyProvInfo(pCert, dwFlags, pvReserved) = DLL("CRYPT32.dll", "bool CryptFindCertificateKeyProvInfo(void*, dword, void*)")
# 呼び出し: CryptFindCertificateKeyProvInfo(pCert, dwFlags, pvReserved)
# pCert : CERT_CONTEXT* -> "void*"
# dwFlags : CRYPT_FIND_FLAGS -> "dword"
# pvReserved : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。