ホーム › Security.Cryptography › CryptHashCertificate
CryptHashCertificate
関数指定アルゴリズムでエンコード済み証明書のハッシュを計算する。
シグネチャ
// CRYPT32.dll
#include <windows.h>
BOOL CryptHashCertificate(
HCRYPTPROV_LEGACY hCryptProv, // optional
ALG_ID Algid,
DWORD dwFlags,
const BYTE* pbEncoded,
DWORD cbEncoded,
BYTE* pbComputedHash, // optional
DWORD* pcbComputedHash
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hCryptProv | HCRYPTPROV_LEGACY | inoptional | このパラメーターは使用されないため、NULL を設定してください。 Windows Server 2003 および Windows XP: ハッシュの計算に使用する 暗号化サービス プロバイダー (CSP) のハンドル。 このパラメーターのデータ型は HCRYPTPROV です。 hCryptProv に特定の CSP を渡す明確な理由がない限り、ゼロを渡します。ゼロを渡すと、ハッシュ、署名検証、または受信者の暗号化操作を行う前に、既定の RSA または Digital Signature Standard (DSS) プロバイダーが取得されます。 |
| Algid | ALG_ID | in | 使用する ハッシュ アルゴリズム を指定する ALG_ID 構造体。Algid がゼロの場合は、既定のハッシュ アルゴリズムである SHA1 が使用されます。 |
| dwFlags | DWORD | in | ハッシュ API に渡される値。詳細については、 CryptCreateHash を参照してください。 |
| pbEncoded | BYTE* | in | ハッシュ化するエンコード済みコンテンツのアドレス。 |
| cbEncoded | DWORD | in | エンコード済みコンテンツのサイズ (バイト単位)。 |
| pbComputedHash | BYTE* | outoptional | 計算されたハッシュを受け取るバッファーへのポインター。 メモリ割り当てのためにこの情報のサイズを設定するには、このパラメーターを NULL にできます。詳細については、 Retrieving Data of Unknown Length を参照してください。 |
| pcbComputedHash | DWORD* | inout | pbComputedHash パラメーターが指すバッファーのサイズ (バイト単位) を格納する DWORD へのポインター。関数が戻るとき、この DWORD にはバッファーに格納されたバイト数が格納されます。 注意 バッファーで返されるデータを処理する際、アプリケーションは返されたデータの実際のサイズを使用する必要があります。実際のサイズは、入力時に指定したバッファーのサイズよりわずかに小さくなる場合があります。入力時には、想定される最大の出力データがバッファーに収まるように、通常は十分に大きいバッファー サイズが指定されます。出力時には、このパラメーターが指す変数が、バッファーにコピーされたデータの実際のサイズを反映するように更新されます。
|
戻り値の型: BOOL
公式ドキュメント
CryptHashCertificate 関数は、署名を含む証明書のエンコード済みコンテンツ全体をハッシュ化します。
戻り値
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// CRYPT32.dll
#include <windows.h>
BOOL CryptHashCertificate(
HCRYPTPROV_LEGACY hCryptProv, // optional
ALG_ID Algid,
DWORD dwFlags,
const BYTE* pbEncoded,
DWORD cbEncoded,
BYTE* pbComputedHash, // optional
DWORD* pcbComputedHash
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CryptHashCertificate(
UIntPtr hCryptProv, // HCRYPTPROV_LEGACY optional
uint Algid, // ALG_ID
uint dwFlags, // DWORD
IntPtr pbEncoded, // BYTE*
uint cbEncoded, // DWORD
IntPtr pbComputedHash, // BYTE* optional, out
ref uint pcbComputedHash // DWORD* in/out
);<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CryptHashCertificate(
hCryptProv As UIntPtr, ' HCRYPTPROV_LEGACY optional
Algid As UInteger, ' ALG_ID
dwFlags As UInteger, ' DWORD
pbEncoded As IntPtr, ' BYTE*
cbEncoded As UInteger, ' DWORD
pbComputedHash As IntPtr, ' BYTE* optional, out
ByRef pcbComputedHash As UInteger ' DWORD* in/out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hCryptProv : HCRYPTPROV_LEGACY optional
' Algid : ALG_ID
' dwFlags : DWORD
' pbEncoded : BYTE*
' cbEncoded : DWORD
' pbComputedHash : BYTE* optional, out
' pcbComputedHash : DWORD* in/out
Declare PtrSafe Function CryptHashCertificate Lib "crypt32" ( _
ByVal hCryptProv As LongPtr, _
ByVal Algid As Long, _
ByVal dwFlags As Long, _
ByVal pbEncoded As LongPtr, _
ByVal cbEncoded As Long, _
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
CryptHashCertificate = ctypes.windll.crypt32.CryptHashCertificate
CryptHashCertificate.restype = wintypes.BOOL
CryptHashCertificate.argtypes = [
ctypes.c_size_t, # hCryptProv : HCRYPTPROV_LEGACY optional
wintypes.DWORD, # Algid : ALG_ID
wintypes.DWORD, # dwFlags : DWORD
ctypes.POINTER(ctypes.c_ubyte), # pbEncoded : BYTE*
wintypes.DWORD, # cbEncoded : DWORD
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')
CryptHashCertificate = Fiddle::Function.new(
lib['CryptHashCertificate'],
[
Fiddle::TYPE_UINTPTR_T, # hCryptProv : HCRYPTPROV_LEGACY optional
-Fiddle::TYPE_INT, # Algid : ALG_ID
-Fiddle::TYPE_INT, # dwFlags : DWORD
Fiddle::TYPE_VOIDP, # pbEncoded : BYTE*
-Fiddle::TYPE_INT, # cbEncoded : DWORD
Fiddle::TYPE_VOIDP, # pbComputedHash : BYTE* optional, out
Fiddle::TYPE_VOIDP, # pcbComputedHash : DWORD* in/out
],
Fiddle::TYPE_INT)#[link(name = "crypt32")]
extern "system" {
fn CryptHashCertificate(
hCryptProv: usize, // HCRYPTPROV_LEGACY optional
Algid: u32, // ALG_ID
dwFlags: u32, // DWORD
pbEncoded: *const u8, // BYTE*
cbEncoded: u32, // DWORD
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 CryptHashCertificate(UIntPtr hCryptProv, uint Algid, uint dwFlags, IntPtr pbEncoded, uint cbEncoded, IntPtr pbComputedHash, ref uint pcbComputedHash);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CryptHashCertificate' -Namespace Win32 -PassThru
# $api::CryptHashCertificate(hCryptProv, Algid, dwFlags, pbEncoded, cbEncoded, pbComputedHash, pcbComputedHash)#uselib "CRYPT32.dll"
#func global CryptHashCertificate "CryptHashCertificate" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; CryptHashCertificate hCryptProv, Algid, dwFlags, varptr(pbEncoded), cbEncoded, varptr(pbComputedHash), varptr(pcbComputedHash) ; 戻り値は stat
; hCryptProv : HCRYPTPROV_LEGACY optional -> "sptr"
; Algid : ALG_ID -> "sptr"
; dwFlags : DWORD -> "sptr"
; pbEncoded : BYTE* -> "sptr"
; cbEncoded : DWORD -> "sptr"
; pbComputedHash : BYTE* optional, out -> "sptr"
; pcbComputedHash : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "CRYPT32.dll" #cfunc global CryptHashCertificate "CryptHashCertificate" sptr, int, int, var, int, var, var ; res = CryptHashCertificate(hCryptProv, Algid, dwFlags, pbEncoded, cbEncoded, pbComputedHash, pcbComputedHash) ; hCryptProv : HCRYPTPROV_LEGACY optional -> "sptr" ; Algid : ALG_ID -> "int" ; dwFlags : DWORD -> "int" ; pbEncoded : BYTE* -> "var" ; cbEncoded : DWORD -> "int" ; pbComputedHash : BYTE* optional, out -> "var" ; pcbComputedHash : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "CRYPT32.dll" #cfunc global CryptHashCertificate "CryptHashCertificate" sptr, int, int, sptr, int, sptr, sptr ; res = CryptHashCertificate(hCryptProv, Algid, dwFlags, varptr(pbEncoded), cbEncoded, varptr(pbComputedHash), varptr(pcbComputedHash)) ; hCryptProv : HCRYPTPROV_LEGACY optional -> "sptr" ; Algid : ALG_ID -> "int" ; dwFlags : DWORD -> "int" ; pbEncoded : BYTE* -> "sptr" ; cbEncoded : DWORD -> "int" ; pbComputedHash : BYTE* optional, out -> "sptr" ; pcbComputedHash : DWORD* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL CryptHashCertificate(HCRYPTPROV_LEGACY hCryptProv, ALG_ID Algid, DWORD dwFlags, BYTE* pbEncoded, DWORD cbEncoded, BYTE* pbComputedHash, DWORD* pcbComputedHash) #uselib "CRYPT32.dll" #cfunc global CryptHashCertificate "CryptHashCertificate" intptr, int, int, var, int, var, var ; res = CryptHashCertificate(hCryptProv, Algid, dwFlags, pbEncoded, cbEncoded, pbComputedHash, pcbComputedHash) ; hCryptProv : HCRYPTPROV_LEGACY optional -> "intptr" ; Algid : ALG_ID -> "int" ; dwFlags : DWORD -> "int" ; pbEncoded : BYTE* -> "var" ; cbEncoded : DWORD -> "int" ; pbComputedHash : BYTE* optional, out -> "var" ; pcbComputedHash : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL CryptHashCertificate(HCRYPTPROV_LEGACY hCryptProv, ALG_ID Algid, DWORD dwFlags, BYTE* pbEncoded, DWORD cbEncoded, BYTE* pbComputedHash, DWORD* pcbComputedHash) #uselib "CRYPT32.dll" #cfunc global CryptHashCertificate "CryptHashCertificate" intptr, int, int, intptr, int, intptr, intptr ; res = CryptHashCertificate(hCryptProv, Algid, dwFlags, varptr(pbEncoded), cbEncoded, varptr(pbComputedHash), varptr(pcbComputedHash)) ; hCryptProv : HCRYPTPROV_LEGACY optional -> "intptr" ; Algid : ALG_ID -> "int" ; dwFlags : DWORD -> "int" ; pbEncoded : BYTE* -> "intptr" ; cbEncoded : DWORD -> "int" ; 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")
procCryptHashCertificate = crypt32.NewProc("CryptHashCertificate")
)
// hCryptProv (HCRYPTPROV_LEGACY optional), Algid (ALG_ID), dwFlags (DWORD), pbEncoded (BYTE*), cbEncoded (DWORD), pbComputedHash (BYTE* optional, out), pcbComputedHash (DWORD* in/out)
r1, _, err := procCryptHashCertificate.Call(
uintptr(hCryptProv),
uintptr(Algid),
uintptr(dwFlags),
uintptr(pbEncoded),
uintptr(cbEncoded),
uintptr(pbComputedHash),
uintptr(pcbComputedHash),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CryptHashCertificate(
hCryptProv: NativeUInt; // HCRYPTPROV_LEGACY optional
Algid: DWORD; // ALG_ID
dwFlags: DWORD; // DWORD
pbEncoded: Pointer; // BYTE*
cbEncoded: DWORD; // DWORD
pbComputedHash: Pointer; // BYTE* optional, out
pcbComputedHash: Pointer // DWORD* in/out
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CryptHashCertificate';result := DllCall("CRYPT32\CryptHashCertificate"
, "UPtr", hCryptProv ; HCRYPTPROV_LEGACY optional
, "UInt", Algid ; ALG_ID
, "UInt", dwFlags ; DWORD
, "Ptr", pbEncoded ; BYTE*
, "UInt", cbEncoded ; DWORD
, "Ptr", pbComputedHash ; BYTE* optional, out
, "Ptr", pcbComputedHash ; DWORD* in/out
, "Int") ; return: BOOL●CryptHashCertificate(hCryptProv, Algid, dwFlags, pbEncoded, cbEncoded, pbComputedHash, pcbComputedHash) = DLL("CRYPT32.dll", "bool CryptHashCertificate(int, dword, dword, void*, dword, void*, void*)")
# 呼び出し: CryptHashCertificate(hCryptProv, Algid, dwFlags, pbEncoded, cbEncoded, pbComputedHash, pcbComputedHash)
# hCryptProv : HCRYPTPROV_LEGACY optional -> "int"
# Algid : ALG_ID -> "dword"
# dwFlags : DWORD -> "dword"
# pbEncoded : BYTE* -> "void*"
# cbEncoded : DWORD -> "dword"
# pbComputedHash : BYTE* optional, out -> "void*"
# pcbComputedHash : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "crypt32" fn CryptHashCertificate(
hCryptProv: usize, // HCRYPTPROV_LEGACY optional
Algid: u32, // ALG_ID
dwFlags: u32, // DWORD
pbEncoded: [*c]u8, // BYTE*
cbEncoded: u32, // DWORD
pbComputedHash: [*c]u8, // BYTE* optional, out
pcbComputedHash: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) i32;proc CryptHashCertificate(
hCryptProv: uint, # HCRYPTPROV_LEGACY optional
Algid: uint32, # ALG_ID
dwFlags: uint32, # DWORD
pbEncoded: ptr uint8, # BYTE*
cbEncoded: uint32, # DWORD
pbComputedHash: ptr uint8, # BYTE* optional, out
pcbComputedHash: ptr uint32 # DWORD* in/out
): int32 {.importc: "CryptHashCertificate", stdcall, dynlib: "CRYPT32.dll".}pragma(lib, "crypt32");
extern(Windows)
int CryptHashCertificate(
size_t hCryptProv, // HCRYPTPROV_LEGACY optional
uint Algid, // ALG_ID
uint dwFlags, // DWORD
ubyte* pbEncoded, // BYTE*
uint cbEncoded, // DWORD
ubyte* pbComputedHash, // BYTE* optional, out
uint* pcbComputedHash // DWORD* in/out
);ccall((:CryptHashCertificate, "CRYPT32.dll"), stdcall, Int32,
(Csize_t, UInt32, UInt32, Ptr{UInt8}, UInt32, Ptr{UInt8}, Ptr{UInt32}),
hCryptProv, Algid, dwFlags, pbEncoded, cbEncoded, pbComputedHash, pcbComputedHash)
# hCryptProv : HCRYPTPROV_LEGACY optional -> Csize_t
# Algid : ALG_ID -> UInt32
# dwFlags : DWORD -> UInt32
# pbEncoded : BYTE* -> Ptr{UInt8}
# cbEncoded : DWORD -> UInt32
# pbComputedHash : BYTE* optional, out -> Ptr{UInt8}
# pcbComputedHash : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t CryptHashCertificate(
uintptr_t hCryptProv,
uint32_t Algid,
uint32_t dwFlags,
uint8_t* pbEncoded,
uint32_t cbEncoded,
uint8_t* pbComputedHash,
uint32_t* pcbComputedHash);
]]
local crypt32 = ffi.load("crypt32")
-- crypt32.CryptHashCertificate(hCryptProv, Algid, dwFlags, pbEncoded, cbEncoded, pbComputedHash, pcbComputedHash)
-- hCryptProv : HCRYPTPROV_LEGACY optional
-- Algid : ALG_ID
-- dwFlags : DWORD
-- pbEncoded : BYTE*
-- cbEncoded : DWORD
-- pbComputedHash : BYTE* optional, out
-- pcbComputedHash : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('CRYPT32.dll');
const CryptHashCertificate = lib.func('__stdcall', 'CryptHashCertificate', 'int32_t', ['uintptr_t', 'uint32_t', 'uint32_t', 'uint8_t *', 'uint32_t', 'uint8_t *', 'uint32_t *']);
// CryptHashCertificate(hCryptProv, Algid, dwFlags, pbEncoded, cbEncoded, pbComputedHash, pcbComputedHash)
// hCryptProv : HCRYPTPROV_LEGACY optional -> 'uintptr_t'
// Algid : ALG_ID -> 'uint32_t'
// dwFlags : DWORD -> 'uint32_t'
// pbEncoded : BYTE* -> 'uint8_t *'
// cbEncoded : DWORD -> 'uint32_t'
// pbComputedHash : BYTE* optional, out -> 'uint8_t *'
// pcbComputedHash : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("CRYPT32.dll", {
CryptHashCertificate: { parameters: ["usize", "u32", "u32", "pointer", "u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.CryptHashCertificate(hCryptProv, Algid, dwFlags, pbEncoded, cbEncoded, pbComputedHash, pcbComputedHash)
// hCryptProv : HCRYPTPROV_LEGACY optional -> "usize"
// Algid : ALG_ID -> "u32"
// dwFlags : DWORD -> "u32"
// pbEncoded : BYTE* -> "pointer"
// cbEncoded : DWORD -> "u32"
// pbComputedHash : BYTE* optional, out -> "pointer"
// pcbComputedHash : DWORD* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CryptHashCertificate(
size_t hCryptProv,
uint32_t Algid,
uint32_t dwFlags,
uint8_t* pbEncoded,
uint32_t cbEncoded,
uint8_t* pbComputedHash,
uint32_t* pcbComputedHash);
C, "CRYPT32.dll");
// $ffi->CryptHashCertificate(hCryptProv, Algid, dwFlags, pbEncoded, cbEncoded, pbComputedHash, pcbComputedHash);
// hCryptProv : HCRYPTPROV_LEGACY optional
// Algid : ALG_ID
// dwFlags : DWORD
// pbEncoded : BYTE*
// cbEncoded : DWORD
// pbComputedHash : BYTE* optional, out
// pcbComputedHash : DWORD* in/out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Crypt32 extends StdCallLibrary {
Crypt32 INSTANCE = Native.load("crypt32", Crypt32.class);
boolean CryptHashCertificate(
long hCryptProv, // HCRYPTPROV_LEGACY optional
int Algid, // ALG_ID
int dwFlags, // DWORD
byte[] pbEncoded, // BYTE*
int cbEncoded, // DWORD
byte[] pbComputedHash, // BYTE* optional, out
IntByReference pcbComputedHash // DWORD* in/out
);
}@[Link("crypt32")]
lib LibCRYPT32
fun CryptHashCertificate = CryptHashCertificate(
hCryptProv : LibC::SizeT, # HCRYPTPROV_LEGACY optional
Algid : UInt32, # ALG_ID
dwFlags : UInt32, # DWORD
pbEncoded : UInt8*, # BYTE*
cbEncoded : UInt32, # DWORD
pbComputedHash : UInt8*, # BYTE* optional, out
pcbComputedHash : UInt32* # DWORD* in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CryptHashCertificateNative = Int32 Function(UintPtr, Uint32, Uint32, Pointer<Uint8>, Uint32, Pointer<Uint8>, Pointer<Uint32>);
typedef CryptHashCertificateDart = int Function(int, int, int, Pointer<Uint8>, int, Pointer<Uint8>, Pointer<Uint32>);
final CryptHashCertificate = DynamicLibrary.open('CRYPT32.dll')
.lookupFunction<CryptHashCertificateNative, CryptHashCertificateDart>('CryptHashCertificate');
// hCryptProv : HCRYPTPROV_LEGACY optional -> UintPtr
// Algid : ALG_ID -> Uint32
// dwFlags : DWORD -> Uint32
// pbEncoded : BYTE* -> Pointer<Uint8>
// cbEncoded : DWORD -> Uint32
// pbComputedHash : BYTE* optional, out -> Pointer<Uint8>
// pcbComputedHash : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CryptHashCertificate(
hCryptProv: NativeUInt; // HCRYPTPROV_LEGACY optional
Algid: DWORD; // ALG_ID
dwFlags: DWORD; // DWORD
pbEncoded: Pointer; // BYTE*
cbEncoded: DWORD; // DWORD
pbComputedHash: Pointer; // BYTE* optional, out
pcbComputedHash: Pointer // DWORD* in/out
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CryptHashCertificate';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CryptHashCertificate"
c_CryptHashCertificate :: CUIntPtr -> Word32 -> Word32 -> Ptr Word8 -> Word32 -> Ptr Word8 -> Ptr Word32 -> IO CInt
-- hCryptProv : HCRYPTPROV_LEGACY optional -> CUIntPtr
-- Algid : ALG_ID -> Word32
-- dwFlags : DWORD -> Word32
-- pbEncoded : BYTE* -> Ptr Word8
-- cbEncoded : DWORD -> Word32
-- pbComputedHash : BYTE* optional, out -> Ptr Word8
-- pcbComputedHash : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let crypthashcertificate =
foreign "CryptHashCertificate"
(size_t @-> uint32_t @-> uint32_t @-> (ptr uint8_t) @-> uint32_t @-> (ptr uint8_t) @-> (ptr uint32_t) @-> returning int32_t)
(* hCryptProv : HCRYPTPROV_LEGACY optional -> size_t *)
(* Algid : ALG_ID -> uint32_t *)
(* dwFlags : DWORD -> uint32_t *)
(* pbEncoded : BYTE* -> (ptr uint8_t) *)
(* cbEncoded : DWORD -> uint32_t *)
(* pbComputedHash : BYTE* optional, out -> (ptr uint8_t) *)
(* pcbComputedHash : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library crypt32 (t "CRYPT32.dll"))
(cffi:use-foreign-library crypt32)
(cffi:defcfun ("CryptHashCertificate" crypt-hash-certificate :convention :stdcall) :int32
(h-crypt-prov :uint64) ; HCRYPTPROV_LEGACY optional
(algid :uint32) ; ALG_ID
(dw-flags :uint32) ; DWORD
(pb-encoded :pointer) ; BYTE*
(cb-encoded :uint32) ; DWORD
(pb-computed-hash :pointer) ; BYTE* optional, out
(pcb-computed-hash :pointer)) ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CryptHashCertificate = Win32::API::More->new('CRYPT32',
'BOOL CryptHashCertificate(WPARAM hCryptProv, DWORD Algid, DWORD dwFlags, LPVOID pbEncoded, DWORD cbEncoded, LPVOID pbComputedHash, LPVOID pcbComputedHash)');
# my $ret = $CryptHashCertificate->Call($hCryptProv, $Algid, $dwFlags, $pbEncoded, $cbEncoded, $pbComputedHash, $pcbComputedHash);
# hCryptProv : HCRYPTPROV_LEGACY optional -> WPARAM
# Algid : ALG_ID -> DWORD
# dwFlags : DWORD -> DWORD
# pbEncoded : BYTE* -> LPVOID
# cbEncoded : DWORD -> DWORD
# pbComputedHash : BYTE* optional, out -> LPVOID
# pcbComputedHash : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
類似 API
- f CryptHashCertificate2 — CNGハッシュアルゴリズムでエンコード済みデータのハッシュを計算する。
公式の関連項目
- f CryptHashPublicKeyInfo — 公開鍵情報のハッシュ値を計算する。
- f CryptHashToBeSigned — エンコードされた証明書の被署名部分のハッシュを計算する。
使用する型