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

CryptVerifyMessageSignatureWithKey

関数
指定した公開鍵情報でメッセージ署名を検証する。
DLLCRYPT32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL CryptVerifyMessageSignatureWithKey(
    CRYPT_KEY_VERIFY_MESSAGE_PARA* pVerifyPara,
    CERT_PUBLIC_KEY_INFO* pPublicKeyInfo,   // optional
    const BYTE* pbSignedBlob,
    DWORD cbSignedBlob,
    BYTE* pbDecoded,   // optional
    DWORD* pcbDecoded   // optional
);

パラメーター

名前方向説明
pVerifyParaCRYPT_KEY_VERIFY_MESSAGE_PARA*in検証パラメーターを格納した CRYPT_KEY_VERIFY_MESSAGE_PARA 構造体へのポインター。
pPublicKeyInfoCERT_PUBLIC_KEY_INFO*inoptional署名されたメッセージの検証に使用する公開鍵を格納した CERT_PUBLIC_KEY_INFO 構造体へのポインター。NULL の場合、署名は検証されません。
pbSignedBlobBYTE*in署名されたメッセージを格納したバッファーへのポインター。
cbSignedBlobDWORDin署名されたメッセージバッファーのサイズ(バイト単位)。
pbDecodedBYTE*outoptional

デコードされたメッセージを受け取るバッファーへのポインター。

デコードされたメッセージが追加処理に不要な場合、またはメモリ割り当てのためにメッセージのサイズを取得する場合は、このパラメーターを NULL にできます。詳細については、 Retrieving Data of Unknown Length を参照してください。

pcbDecodedDWORD*inoutoptional

pbDecoded バッファーのサイズ(バイト単位)を指定する DWORD 値へのポインター。関数が戻るとき、この DWORD にはデコードされたメッセージのサイズ(バイト単位)が格納されます。このパラメーターが NULL の場合、デコードされたメッセージは返されません。

返されたデータを処理する際、アプリケーションは返されたデータの実際のサイズを使用する必要があります。実際のサイズは、入力時に指定したバッファーのサイズよりわずかに小さくなることがあります。(入力時には、出力データが最大になっても収まるように、通常はバッファーサイズを十分大きく指定します。) 出力時には、このパラメーターが指すバッファーがバッファーにコピーされたデータの実際のサイズを反映するように更新されます。

戻り値の型: BOOL

公式ドキュメント

指定された公開鍵情報を使用して、署名されたメッセージの署名を検証します。

戻り値

関数が成功した場合、0 以外を返します。

関数が失敗した場合、0 を返します。拡張エラー情報を取得するには、 GetLastError を呼び出します。

次の表に、 GetLastError 関数によって最も一般的に返されるエラーコードを示します。

戻り値コード 説明
ERROR_MORE_DATA
pbDecoded パラメーターで指定されたバッファーが返されるデータを保持するのに十分な大きさでない場合、関数は ERROR_MORE_DATA コードを設定し、必要なバッファーサイズ(バイト単位)を pcbDecoded が指す変数に格納します。
E_INVALIDARG
メッセージおよび証明書のエンコードの種類が無効です。現在、PKCS_7_ASN_ENCODING と X509_ASN_ENCODING_TYPE のみがサポートされています。*pVerifyPara 内の cbSize が無効です。
CRYPT_E_UNEXPECTED_MSG_TYPE
署名された暗号化メッセージではありません。
CRYPT_E_NO_SIGNER
メッセージに署名者が存在しないか、指定された dwSignerIndex に対応する署名者が存在しません。
NTE_BAD_ALGID
メッセージは、不明またはサポートされていないアルゴリズムを使用してハッシュおよび署名されました。
NTE_BAD_SIGNATURE
メッセージの署名が検証されませんでした。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

BOOL CryptVerifyMessageSignatureWithKey(
    CRYPT_KEY_VERIFY_MESSAGE_PARA* pVerifyPara,
    CERT_PUBLIC_KEY_INFO* pPublicKeyInfo,   // optional
    const BYTE* pbSignedBlob,
    DWORD cbSignedBlob,
    BYTE* pbDecoded,   // optional
    DWORD* pcbDecoded   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CryptVerifyMessageSignatureWithKey(
    IntPtr pVerifyPara,   // CRYPT_KEY_VERIFY_MESSAGE_PARA*
    IntPtr pPublicKeyInfo,   // CERT_PUBLIC_KEY_INFO* optional
    IntPtr pbSignedBlob,   // BYTE*
    uint cbSignedBlob,   // DWORD
    IntPtr pbDecoded,   // BYTE* optional, out
    IntPtr pcbDecoded   // DWORD* optional, in/out
);
<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CryptVerifyMessageSignatureWithKey(
    pVerifyPara As IntPtr,   ' CRYPT_KEY_VERIFY_MESSAGE_PARA*
    pPublicKeyInfo As IntPtr,   ' CERT_PUBLIC_KEY_INFO* optional
    pbSignedBlob As IntPtr,   ' BYTE*
    cbSignedBlob As UInteger,   ' DWORD
    pbDecoded As IntPtr,   ' BYTE* optional, out
    pcbDecoded As IntPtr   ' DWORD* optional, in/out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' pVerifyPara : CRYPT_KEY_VERIFY_MESSAGE_PARA*
' pPublicKeyInfo : CERT_PUBLIC_KEY_INFO* optional
' pbSignedBlob : BYTE*
' cbSignedBlob : DWORD
' pbDecoded : BYTE* optional, out
' pcbDecoded : DWORD* optional, in/out
Declare PtrSafe Function CryptVerifyMessageSignatureWithKey Lib "crypt32" ( _
    ByVal pVerifyPara As LongPtr, _
    ByVal pPublicKeyInfo As LongPtr, _
    ByVal pbSignedBlob As LongPtr, _
    ByVal cbSignedBlob As Long, _
    ByVal pbDecoded As LongPtr, _
    ByVal pcbDecoded As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CryptVerifyMessageSignatureWithKey = ctypes.windll.crypt32.CryptVerifyMessageSignatureWithKey
CryptVerifyMessageSignatureWithKey.restype = wintypes.BOOL
CryptVerifyMessageSignatureWithKey.argtypes = [
    ctypes.c_void_p,  # pVerifyPara : CRYPT_KEY_VERIFY_MESSAGE_PARA*
    ctypes.c_void_p,  # pPublicKeyInfo : CERT_PUBLIC_KEY_INFO* optional
    ctypes.POINTER(ctypes.c_ubyte),  # pbSignedBlob : BYTE*
    wintypes.DWORD,  # cbSignedBlob : DWORD
    ctypes.POINTER(ctypes.c_ubyte),  # pbDecoded : BYTE* optional, out
    ctypes.POINTER(wintypes.DWORD),  # pcbDecoded : DWORD* optional, in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
	procCryptVerifyMessageSignatureWithKey = crypt32.NewProc("CryptVerifyMessageSignatureWithKey")
)

// pVerifyPara (CRYPT_KEY_VERIFY_MESSAGE_PARA*), pPublicKeyInfo (CERT_PUBLIC_KEY_INFO* optional), pbSignedBlob (BYTE*), cbSignedBlob (DWORD), pbDecoded (BYTE* optional, out), pcbDecoded (DWORD* optional, in/out)
r1, _, err := procCryptVerifyMessageSignatureWithKey.Call(
	uintptr(pVerifyPara),
	uintptr(pPublicKeyInfo),
	uintptr(pbSignedBlob),
	uintptr(cbSignedBlob),
	uintptr(pbDecoded),
	uintptr(pcbDecoded),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function CryptVerifyMessageSignatureWithKey(
  pVerifyPara: Pointer;   // CRYPT_KEY_VERIFY_MESSAGE_PARA*
  pPublicKeyInfo: Pointer;   // CERT_PUBLIC_KEY_INFO* optional
  pbSignedBlob: Pointer;   // BYTE*
  cbSignedBlob: DWORD;   // DWORD
  pbDecoded: Pointer;   // BYTE* optional, out
  pcbDecoded: Pointer   // DWORD* optional, in/out
): BOOL; stdcall;
  external 'CRYPT32.dll' name 'CryptVerifyMessageSignatureWithKey';
result := DllCall("CRYPT32\CryptVerifyMessageSignatureWithKey"
    , "Ptr", pVerifyPara   ; CRYPT_KEY_VERIFY_MESSAGE_PARA*
    , "Ptr", pPublicKeyInfo   ; CERT_PUBLIC_KEY_INFO* optional
    , "Ptr", pbSignedBlob   ; BYTE*
    , "UInt", cbSignedBlob   ; DWORD
    , "Ptr", pbDecoded   ; BYTE* optional, out
    , "Ptr", pcbDecoded   ; DWORD* optional, in/out
    , "Int")   ; return: BOOL
●CryptVerifyMessageSignatureWithKey(pVerifyPara, pPublicKeyInfo, pbSignedBlob, cbSignedBlob, pbDecoded, pcbDecoded) = DLL("CRYPT32.dll", "bool CryptVerifyMessageSignatureWithKey(void*, void*, void*, dword, void*, void*)")
# 呼び出し: CryptVerifyMessageSignatureWithKey(pVerifyPara, pPublicKeyInfo, pbSignedBlob, cbSignedBlob, pbDecoded, pcbDecoded)
# pVerifyPara : CRYPT_KEY_VERIFY_MESSAGE_PARA* -> "void*"
# pPublicKeyInfo : CERT_PUBLIC_KEY_INFO* optional -> "void*"
# pbSignedBlob : BYTE* -> "void*"
# cbSignedBlob : DWORD -> "dword"
# pbDecoded : BYTE* optional, out -> "void*"
# pcbDecoded : DWORD* optional, in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "crypt32" fn CryptVerifyMessageSignatureWithKey(
    pVerifyPara: [*c]CRYPT_KEY_VERIFY_MESSAGE_PARA, // CRYPT_KEY_VERIFY_MESSAGE_PARA*
    pPublicKeyInfo: [*c]CERT_PUBLIC_KEY_INFO, // CERT_PUBLIC_KEY_INFO* optional
    pbSignedBlob: [*c]u8, // BYTE*
    cbSignedBlob: u32, // DWORD
    pbDecoded: [*c]u8, // BYTE* optional, out
    pcbDecoded: [*c]u32 // DWORD* optional, in/out
) callconv(std.os.windows.WINAPI) i32;
proc CryptVerifyMessageSignatureWithKey(
    pVerifyPara: ptr CRYPT_KEY_VERIFY_MESSAGE_PARA,  # CRYPT_KEY_VERIFY_MESSAGE_PARA*
    pPublicKeyInfo: ptr CERT_PUBLIC_KEY_INFO,  # CERT_PUBLIC_KEY_INFO* optional
    pbSignedBlob: ptr uint8,  # BYTE*
    cbSignedBlob: uint32,  # DWORD
    pbDecoded: ptr uint8,  # BYTE* optional, out
    pcbDecoded: ptr uint32  # DWORD* optional, in/out
): int32 {.importc: "CryptVerifyMessageSignatureWithKey", stdcall, dynlib: "CRYPT32.dll".}
pragma(lib, "crypt32");
extern(Windows)
int CryptVerifyMessageSignatureWithKey(
    CRYPT_KEY_VERIFY_MESSAGE_PARA* pVerifyPara,   // CRYPT_KEY_VERIFY_MESSAGE_PARA*
    CERT_PUBLIC_KEY_INFO* pPublicKeyInfo,   // CERT_PUBLIC_KEY_INFO* optional
    ubyte* pbSignedBlob,   // BYTE*
    uint cbSignedBlob,   // DWORD
    ubyte* pbDecoded,   // BYTE* optional, out
    uint* pcbDecoded   // DWORD* optional, in/out
);
ccall((:CryptVerifyMessageSignatureWithKey, "CRYPT32.dll"), stdcall, Int32,
      (Ptr{CRYPT_KEY_VERIFY_MESSAGE_PARA}, Ptr{CERT_PUBLIC_KEY_INFO}, Ptr{UInt8}, UInt32, Ptr{UInt8}, Ptr{UInt32}),
      pVerifyPara, pPublicKeyInfo, pbSignedBlob, cbSignedBlob, pbDecoded, pcbDecoded)
# pVerifyPara : CRYPT_KEY_VERIFY_MESSAGE_PARA* -> Ptr{CRYPT_KEY_VERIFY_MESSAGE_PARA}
# pPublicKeyInfo : CERT_PUBLIC_KEY_INFO* optional -> Ptr{CERT_PUBLIC_KEY_INFO}
# pbSignedBlob : BYTE* -> Ptr{UInt8}
# cbSignedBlob : DWORD -> UInt32
# pbDecoded : BYTE* optional, out -> Ptr{UInt8}
# pcbDecoded : DWORD* optional, in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t CryptVerifyMessageSignatureWithKey(
    void* pVerifyPara,
    void* pPublicKeyInfo,
    uint8_t* pbSignedBlob,
    uint32_t cbSignedBlob,
    uint8_t* pbDecoded,
    uint32_t* pcbDecoded);
]]
local crypt32 = ffi.load("crypt32")
-- crypt32.CryptVerifyMessageSignatureWithKey(pVerifyPara, pPublicKeyInfo, pbSignedBlob, cbSignedBlob, pbDecoded, pcbDecoded)
-- pVerifyPara : CRYPT_KEY_VERIFY_MESSAGE_PARA*
-- pPublicKeyInfo : CERT_PUBLIC_KEY_INFO* optional
-- pbSignedBlob : BYTE*
-- cbSignedBlob : DWORD
-- pbDecoded : BYTE* optional, out
-- pcbDecoded : DWORD* optional, in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('CRYPT32.dll');
const CryptVerifyMessageSignatureWithKey = lib.func('__stdcall', 'CryptVerifyMessageSignatureWithKey', 'int32_t', ['void *', 'void *', 'uint8_t *', 'uint32_t', 'uint8_t *', 'uint32_t *']);
// CryptVerifyMessageSignatureWithKey(pVerifyPara, pPublicKeyInfo, pbSignedBlob, cbSignedBlob, pbDecoded, pcbDecoded)
// pVerifyPara : CRYPT_KEY_VERIFY_MESSAGE_PARA* -> 'void *'
// pPublicKeyInfo : CERT_PUBLIC_KEY_INFO* optional -> 'void *'
// pbSignedBlob : BYTE* -> 'uint8_t *'
// cbSignedBlob : DWORD -> 'uint32_t'
// pbDecoded : BYTE* optional, out -> 'uint8_t *'
// pcbDecoded : DWORD* optional, in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("CRYPT32.dll", {
  CryptVerifyMessageSignatureWithKey: { parameters: ["pointer", "pointer", "pointer", "u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.CryptVerifyMessageSignatureWithKey(pVerifyPara, pPublicKeyInfo, pbSignedBlob, cbSignedBlob, pbDecoded, pcbDecoded)
// pVerifyPara : CRYPT_KEY_VERIFY_MESSAGE_PARA* -> "pointer"
// pPublicKeyInfo : CERT_PUBLIC_KEY_INFO* optional -> "pointer"
// pbSignedBlob : BYTE* -> "pointer"
// cbSignedBlob : DWORD -> "u32"
// pbDecoded : BYTE* optional, out -> "pointer"
// pcbDecoded : DWORD* optional, in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t CryptVerifyMessageSignatureWithKey(
    void* pVerifyPara,
    void* pPublicKeyInfo,
    uint8_t* pbSignedBlob,
    uint32_t cbSignedBlob,
    uint8_t* pbDecoded,
    uint32_t* pcbDecoded);
C, "CRYPT32.dll");
// $ffi->CryptVerifyMessageSignatureWithKey(pVerifyPara, pPublicKeyInfo, pbSignedBlob, cbSignedBlob, pbDecoded, pcbDecoded);
// pVerifyPara : CRYPT_KEY_VERIFY_MESSAGE_PARA*
// pPublicKeyInfo : CERT_PUBLIC_KEY_INFO* optional
// pbSignedBlob : BYTE*
// cbSignedBlob : DWORD
// pbDecoded : BYTE* optional, out
// pcbDecoded : DWORD* optional, 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 CryptVerifyMessageSignatureWithKey(
        Pointer pVerifyPara,   // CRYPT_KEY_VERIFY_MESSAGE_PARA*
        Pointer pPublicKeyInfo,   // CERT_PUBLIC_KEY_INFO* optional
        byte[] pbSignedBlob,   // BYTE*
        int cbSignedBlob,   // DWORD
        byte[] pbDecoded,   // BYTE* optional, out
        IntByReference pcbDecoded   // DWORD* optional, in/out
    );
}
@[Link("crypt32")]
lib LibCRYPT32
  fun CryptVerifyMessageSignatureWithKey = CryptVerifyMessageSignatureWithKey(
    pVerifyPara : CRYPT_KEY_VERIFY_MESSAGE_PARA*,   # CRYPT_KEY_VERIFY_MESSAGE_PARA*
    pPublicKeyInfo : CERT_PUBLIC_KEY_INFO*,   # CERT_PUBLIC_KEY_INFO* optional
    pbSignedBlob : UInt8*,   # BYTE*
    cbSignedBlob : UInt32,   # DWORD
    pbDecoded : UInt8*,   # BYTE* optional, out
    pcbDecoded : UInt32*   # DWORD* optional, 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 CryptVerifyMessageSignatureWithKeyNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Uint8>, Uint32, Pointer<Uint8>, Pointer<Uint32>);
typedef CryptVerifyMessageSignatureWithKeyDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Uint8>, int, Pointer<Uint8>, Pointer<Uint32>);
final CryptVerifyMessageSignatureWithKey = DynamicLibrary.open('CRYPT32.dll')
    .lookupFunction<CryptVerifyMessageSignatureWithKeyNative, CryptVerifyMessageSignatureWithKeyDart>('CryptVerifyMessageSignatureWithKey');
// pVerifyPara : CRYPT_KEY_VERIFY_MESSAGE_PARA* -> Pointer<Void>
// pPublicKeyInfo : CERT_PUBLIC_KEY_INFO* optional -> Pointer<Void>
// pbSignedBlob : BYTE* -> Pointer<Uint8>
// cbSignedBlob : DWORD -> Uint32
// pbDecoded : BYTE* optional, out -> Pointer<Uint8>
// pcbDecoded : DWORD* optional, in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CryptVerifyMessageSignatureWithKey(
  pVerifyPara: Pointer;   // CRYPT_KEY_VERIFY_MESSAGE_PARA*
  pPublicKeyInfo: Pointer;   // CERT_PUBLIC_KEY_INFO* optional
  pbSignedBlob: Pointer;   // BYTE*
  cbSignedBlob: DWORD;   // DWORD
  pbDecoded: Pointer;   // BYTE* optional, out
  pcbDecoded: Pointer   // DWORD* optional, in/out
): BOOL; stdcall;
  external 'CRYPT32.dll' name 'CryptVerifyMessageSignatureWithKey';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CryptVerifyMessageSignatureWithKey"
  c_CryptVerifyMessageSignatureWithKey :: Ptr () -> Ptr () -> Ptr Word8 -> Word32 -> Ptr Word8 -> Ptr Word32 -> IO CInt
-- pVerifyPara : CRYPT_KEY_VERIFY_MESSAGE_PARA* -> Ptr ()
-- pPublicKeyInfo : CERT_PUBLIC_KEY_INFO* optional -> Ptr ()
-- pbSignedBlob : BYTE* -> Ptr Word8
-- cbSignedBlob : DWORD -> Word32
-- pbDecoded : BYTE* optional, out -> Ptr Word8
-- pcbDecoded : DWORD* optional, in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let cryptverifymessagesignaturewithkey =
  foreign "CryptVerifyMessageSignatureWithKey"
    ((ptr void) @-> (ptr void) @-> (ptr uint8_t) @-> uint32_t @-> (ptr uint8_t) @-> (ptr uint32_t) @-> returning int32_t)
(* pVerifyPara : CRYPT_KEY_VERIFY_MESSAGE_PARA* -> (ptr void) *)
(* pPublicKeyInfo : CERT_PUBLIC_KEY_INFO* optional -> (ptr void) *)
(* pbSignedBlob : BYTE* -> (ptr uint8_t) *)
(* cbSignedBlob : DWORD -> uint32_t *)
(* pbDecoded : BYTE* optional, out -> (ptr uint8_t) *)
(* pcbDecoded : DWORD* optional, 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 ("CryptVerifyMessageSignatureWithKey" crypt-verify-message-signature-with-key :convention :stdcall) :int32
  (p-verify-para :pointer)   ; CRYPT_KEY_VERIFY_MESSAGE_PARA*
  (p-public-key-info :pointer)   ; CERT_PUBLIC_KEY_INFO* optional
  (pb-signed-blob :pointer)   ; BYTE*
  (cb-signed-blob :uint32)   ; DWORD
  (pb-decoded :pointer)   ; BYTE* optional, out
  (pcb-decoded :pointer))   ; DWORD* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CryptVerifyMessageSignatureWithKey = Win32::API::More->new('CRYPT32',
    'BOOL CryptVerifyMessageSignatureWithKey(LPVOID pVerifyPara, LPVOID pPublicKeyInfo, LPVOID pbSignedBlob, DWORD cbSignedBlob, LPVOID pbDecoded, LPVOID pcbDecoded)');
# my $ret = $CryptVerifyMessageSignatureWithKey->Call($pVerifyPara, $pPublicKeyInfo, $pbSignedBlob, $cbSignedBlob, $pbDecoded, $pcbDecoded);
# pVerifyPara : CRYPT_KEY_VERIFY_MESSAGE_PARA* -> LPVOID
# pPublicKeyInfo : CERT_PUBLIC_KEY_INFO* optional -> LPVOID
# pbSignedBlob : BYTE* -> LPVOID
# cbSignedBlob : DWORD -> DWORD
# pbDecoded : BYTE* optional, out -> LPVOID
# pcbDecoded : DWORD* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型