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