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

CryptVerifyMessageSignature

関数
署名付きメッセージの署名を検証し署名者証明書を取得する。
DLLCRYPT32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL CryptVerifyMessageSignature(
    CRYPT_VERIFY_MESSAGE_PARA* pVerifyPara,
    DWORD dwSignerIndex,
    const BYTE* pbSignedBlob,
    DWORD cbSignedBlob,
    BYTE* pbDecoded,   // optional
    DWORD* pcbDecoded,   // optional
    CERT_CONTEXT** ppSignerCert   // optional
);

パラメーター

名前方向
pVerifyParaCRYPT_VERIFY_MESSAGE_PARA*in
dwSignerIndexDWORDin
pbSignedBlobBYTE*in
cbSignedBlobDWORDin
pbDecodedBYTE*outoptional
pcbDecodedDWORD*inoutoptional
ppSignerCertCERT_CONTEXT**outoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

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

CryptVerifyMessageSignature = ctypes.windll.crypt32.CryptVerifyMessageSignature
CryptVerifyMessageSignature.restype = wintypes.BOOL
CryptVerifyMessageSignature.argtypes = [
    ctypes.c_void_p,  # pVerifyPara : CRYPT_VERIFY_MESSAGE_PARA*
    wintypes.DWORD,  # dwSignerIndex : DWORD
    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
    ctypes.c_void_p,  # ppSignerCert : CERT_CONTEXT** optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
	procCryptVerifyMessageSignature = crypt32.NewProc("CryptVerifyMessageSignature")
)

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