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

CertComparePublicKeyInfo

関数
2つの公開鍵情報が一致するかを比較する。
DLLCRYPT32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

BOOL CertComparePublicKeyInfo(
    CERT_QUERY_ENCODING_TYPE dwCertEncodingType,
    CERT_PUBLIC_KEY_INFO* pPublicKey1,
    CERT_PUBLIC_KEY_INFO* pPublicKey2
);

パラメーター

名前方向
dwCertEncodingTypeCERT_QUERY_ENCODING_TYPEin
pPublicKey1CERT_PUBLIC_KEY_INFO*in
pPublicKey2CERT_PUBLIC_KEY_INFO*in

戻り値の型: BOOL

各言語での呼び出し定義

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

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

CertComparePublicKeyInfo = ctypes.windll.crypt32.CertComparePublicKeyInfo
CertComparePublicKeyInfo.restype = wintypes.BOOL
CertComparePublicKeyInfo.argtypes = [
    wintypes.DWORD,  # dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
    ctypes.c_void_p,  # pPublicKey1 : CERT_PUBLIC_KEY_INFO*
    ctypes.c_void_p,  # pPublicKey2 : CERT_PUBLIC_KEY_INFO*
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('CRYPT32.dll')
CertComparePublicKeyInfo = Fiddle::Function.new(
  lib['CertComparePublicKeyInfo'],
  [
    -Fiddle::TYPE_INT,  # dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
    Fiddle::TYPE_VOIDP,  # pPublicKey1 : CERT_PUBLIC_KEY_INFO*
    Fiddle::TYPE_VOIDP,  # pPublicKey2 : CERT_PUBLIC_KEY_INFO*
  ],
  Fiddle::TYPE_INT)
#[link(name = "crypt32")]
extern "system" {
    fn CertComparePublicKeyInfo(
        dwCertEncodingType: u32,  // CERT_QUERY_ENCODING_TYPE
        pPublicKey1: *mut CERT_PUBLIC_KEY_INFO,  // CERT_PUBLIC_KEY_INFO*
        pPublicKey2: *mut CERT_PUBLIC_KEY_INFO  // CERT_PUBLIC_KEY_INFO*
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll")]
public static extern bool CertComparePublicKeyInfo(uint dwCertEncodingType, IntPtr pPublicKey1, IntPtr pPublicKey2);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CertComparePublicKeyInfo' -Namespace Win32 -PassThru
# $api::CertComparePublicKeyInfo(dwCertEncodingType, pPublicKey1, pPublicKey2)
#uselib "CRYPT32.dll"
#func global CertComparePublicKeyInfo "CertComparePublicKeyInfo" sptr, sptr, sptr
; CertComparePublicKeyInfo dwCertEncodingType, varptr(pPublicKey1), varptr(pPublicKey2)   ; 戻り値は stat
; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "sptr"
; pPublicKey1 : CERT_PUBLIC_KEY_INFO* -> "sptr"
; pPublicKey2 : CERT_PUBLIC_KEY_INFO* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "CRYPT32.dll"
#cfunc global CertComparePublicKeyInfo "CertComparePublicKeyInfo" int, var, var
; res = CertComparePublicKeyInfo(dwCertEncodingType, pPublicKey1, pPublicKey2)
; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int"
; pPublicKey1 : CERT_PUBLIC_KEY_INFO* -> "var"
; pPublicKey2 : CERT_PUBLIC_KEY_INFO* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL CertComparePublicKeyInfo(CERT_QUERY_ENCODING_TYPE dwCertEncodingType, CERT_PUBLIC_KEY_INFO* pPublicKey1, CERT_PUBLIC_KEY_INFO* pPublicKey2)
#uselib "CRYPT32.dll"
#cfunc global CertComparePublicKeyInfo "CertComparePublicKeyInfo" int, var, var
; res = CertComparePublicKeyInfo(dwCertEncodingType, pPublicKey1, pPublicKey2)
; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int"
; pPublicKey1 : CERT_PUBLIC_KEY_INFO* -> "var"
; pPublicKey2 : CERT_PUBLIC_KEY_INFO* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
	procCertComparePublicKeyInfo = crypt32.NewProc("CertComparePublicKeyInfo")
)

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