ホーム › Security.Cryptography › CryptVerifyMessageSignatureWithKey
CryptVerifyMessageSignatureWithKey
関数指定した公開鍵情報でメッセージ署名を検証する。
シグネチャ
// 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
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pVerifyPara | CRYPT_KEY_VERIFY_MESSAGE_PARA* | in |
| pPublicKeyInfo | CERT_PUBLIC_KEY_INFO* | inoptional |
| pbSignedBlob | BYTE* | in |
| cbSignedBlob | DWORD | in |
| pbDecoded | BYTE* | outoptional |
| pcbDecoded | DWORD* | inoutoptional |
戻り値の型: BOOL
各言語での呼び出し定義
// 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 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 方式にも切替可。#uselib "CRYPT32.dll" #cfunc global CryptVerifyMessageSignatureWithKey "CryptVerifyMessageSignatureWithKey" sptr, sptr, sptr, int, sptr, sptr ; res = CryptVerifyMessageSignatureWithKey(varptr(pVerifyPara), varptr(pPublicKeyInfo), varptr(pbSignedBlob), cbSignedBlob, varptr(pbDecoded), varptr(pcbDecoded)) ; pVerifyPara : CRYPT_KEY_VERIFY_MESSAGE_PARA* -> "sptr" ; pPublicKeyInfo : CERT_PUBLIC_KEY_INFO* optional -> "sptr" ; pbSignedBlob : BYTE* -> "sptr" ; cbSignedBlob : DWORD -> "int" ; pbDecoded : BYTE* optional, out -> "sptr" ; pcbDecoded : DWORD* optional, in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; 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" intptr, intptr, intptr, int, intptr, intptr ; res = CryptVerifyMessageSignatureWithKey(varptr(pVerifyPara), varptr(pPublicKeyInfo), varptr(pbSignedBlob), cbSignedBlob, varptr(pbDecoded), varptr(pcbDecoded)) ; pVerifyPara : CRYPT_KEY_VERIFY_MESSAGE_PARA* -> "intptr" ; pPublicKeyInfo : CERT_PUBLIC_KEY_INFO* optional -> "intptr" ; pbSignedBlob : BYTE* -> "intptr" ; cbSignedBlob : DWORD -> "int" ; pbDecoded : BYTE* optional, out -> "intptr" ; pcbDecoded : DWORD* optional, in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // BOOLfunction 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)。