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

CryptMsgGetAndVerifySigner

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

シグネチャ

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

BOOL CryptMsgGetAndVerifySigner(
    void* hCryptMsg,
    DWORD cSignerStore,
    HCERTSTORE* rghSignerStore,   // optional
    DWORD dwFlags,
    CERT_CONTEXT** ppSigner,   // optional
    DWORD* pdwSignerIndex   // optional
);

パラメーター

名前方向
hCryptMsgvoid*in
cSignerStoreDWORDin
rghSignerStoreHCERTSTORE*inoptional
dwFlagsDWORDin
ppSignerCERT_CONTEXT**outoptional
pdwSignerIndexDWORD*inoutoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL CryptMsgGetAndVerifySigner(
    void* hCryptMsg,
    DWORD cSignerStore,
    HCERTSTORE* rghSignerStore,   // optional
    DWORD dwFlags,
    CERT_CONTEXT** ppSigner,   // optional
    DWORD* pdwSignerIndex   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CryptMsgGetAndVerifySigner(
    IntPtr hCryptMsg,   // void*
    uint cSignerStore,   // DWORD
    IntPtr rghSignerStore,   // HCERTSTORE* optional
    uint dwFlags,   // DWORD
    IntPtr ppSigner,   // CERT_CONTEXT** optional, out
    IntPtr pdwSignerIndex   // DWORD* optional, in/out
);
<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CryptMsgGetAndVerifySigner(
    hCryptMsg As IntPtr,   ' void*
    cSignerStore As UInteger,   ' DWORD
    rghSignerStore As IntPtr,   ' HCERTSTORE* optional
    dwFlags As UInteger,   ' DWORD
    ppSigner As IntPtr,   ' CERT_CONTEXT** optional, out
    pdwSignerIndex As IntPtr   ' DWORD* optional, in/out
) As Boolean
End Function
' hCryptMsg : void*
' cSignerStore : DWORD
' rghSignerStore : HCERTSTORE* optional
' dwFlags : DWORD
' ppSigner : CERT_CONTEXT** optional, out
' pdwSignerIndex : DWORD* optional, in/out
Declare PtrSafe Function CryptMsgGetAndVerifySigner Lib "crypt32" ( _
    ByVal hCryptMsg As LongPtr, _
    ByVal cSignerStore As Long, _
    ByVal rghSignerStore As LongPtr, _
    ByVal dwFlags As Long, _
    ByVal ppSigner As LongPtr, _
    ByVal pdwSignerIndex As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CryptMsgGetAndVerifySigner = ctypes.windll.crypt32.CryptMsgGetAndVerifySigner
CryptMsgGetAndVerifySigner.restype = wintypes.BOOL
CryptMsgGetAndVerifySigner.argtypes = [
    ctypes.POINTER(None),  # hCryptMsg : void*
    wintypes.DWORD,  # cSignerStore : DWORD
    ctypes.c_void_p,  # rghSignerStore : HCERTSTORE* optional
    wintypes.DWORD,  # dwFlags : DWORD
    ctypes.c_void_p,  # ppSigner : CERT_CONTEXT** optional, out
    ctypes.POINTER(wintypes.DWORD),  # pdwSignerIndex : 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')
CryptMsgGetAndVerifySigner = Fiddle::Function.new(
  lib['CryptMsgGetAndVerifySigner'],
  [
    Fiddle::TYPE_VOIDP,  # hCryptMsg : void*
    -Fiddle::TYPE_INT,  # cSignerStore : DWORD
    Fiddle::TYPE_VOIDP,  # rghSignerStore : HCERTSTORE* optional
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
    Fiddle::TYPE_VOIDP,  # ppSigner : CERT_CONTEXT** optional, out
    Fiddle::TYPE_VOIDP,  # pdwSignerIndex : DWORD* optional, in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "crypt32")]
extern "system" {
    fn CryptMsgGetAndVerifySigner(
        hCryptMsg: *mut (),  // void*
        cSignerStore: u32,  // DWORD
        rghSignerStore: *mut *mut core::ffi::c_void,  // HCERTSTORE* optional
        dwFlags: u32,  // DWORD
        ppSigner: *mut *mut CERT_CONTEXT,  // CERT_CONTEXT** optional, out
        pdwSignerIndex: *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 CryptMsgGetAndVerifySigner(IntPtr hCryptMsg, uint cSignerStore, IntPtr rghSignerStore, uint dwFlags, IntPtr ppSigner, IntPtr pdwSignerIndex);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CryptMsgGetAndVerifySigner' -Namespace Win32 -PassThru
# $api::CryptMsgGetAndVerifySigner(hCryptMsg, cSignerStore, rghSignerStore, dwFlags, ppSigner, pdwSignerIndex)
#uselib "CRYPT32.dll"
#func global CryptMsgGetAndVerifySigner "CryptMsgGetAndVerifySigner" sptr, sptr, sptr, sptr, sptr, sptr
; CryptMsgGetAndVerifySigner hCryptMsg, cSignerStore, rghSignerStore, dwFlags, varptr(ppSigner), varptr(pdwSignerIndex)   ; 戻り値は stat
; hCryptMsg : void* -> "sptr"
; cSignerStore : DWORD -> "sptr"
; rghSignerStore : HCERTSTORE* optional -> "sptr"
; dwFlags : DWORD -> "sptr"
; ppSigner : CERT_CONTEXT** optional, out -> "sptr"
; pdwSignerIndex : DWORD* optional, in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "CRYPT32.dll"
#cfunc global CryptMsgGetAndVerifySigner "CryptMsgGetAndVerifySigner" sptr, int, sptr, int, var, var
; res = CryptMsgGetAndVerifySigner(hCryptMsg, cSignerStore, rghSignerStore, dwFlags, ppSigner, pdwSignerIndex)
; hCryptMsg : void* -> "sptr"
; cSignerStore : DWORD -> "int"
; rghSignerStore : HCERTSTORE* optional -> "sptr"
; dwFlags : DWORD -> "int"
; ppSigner : CERT_CONTEXT** optional, out -> "var"
; pdwSignerIndex : DWORD* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL CryptMsgGetAndVerifySigner(void* hCryptMsg, DWORD cSignerStore, HCERTSTORE* rghSignerStore, DWORD dwFlags, CERT_CONTEXT** ppSigner, DWORD* pdwSignerIndex)
#uselib "CRYPT32.dll"
#cfunc global CryptMsgGetAndVerifySigner "CryptMsgGetAndVerifySigner" intptr, int, intptr, int, var, var
; res = CryptMsgGetAndVerifySigner(hCryptMsg, cSignerStore, rghSignerStore, dwFlags, ppSigner, pdwSignerIndex)
; hCryptMsg : void* -> "intptr"
; cSignerStore : DWORD -> "int"
; rghSignerStore : HCERTSTORE* optional -> "intptr"
; dwFlags : DWORD -> "int"
; ppSigner : CERT_CONTEXT** optional, out -> "var"
; pdwSignerIndex : DWORD* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
	procCryptMsgGetAndVerifySigner = crypt32.NewProc("CryptMsgGetAndVerifySigner")
)

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