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

CryptMsgVerifyCountersignatureEncoded

関数
エンコードされた副署名を検証する。
DLLCRYPT32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL CryptMsgVerifyCountersignatureEncoded(
    HCRYPTPROV_LEGACY hCryptProv,   // optional
    DWORD dwEncodingType,
    BYTE* pbSignerInfo,
    DWORD cbSignerInfo,
    BYTE* pbSignerInfoCountersignature,
    DWORD cbSignerInfoCountersignature,
    CERT_INFO* pciCountersigner
);

パラメーター

名前方向
hCryptProvHCRYPTPROV_LEGACYinoptional
dwEncodingTypeDWORDin
pbSignerInfoBYTE*in
cbSignerInfoDWORDin
pbSignerInfoCountersignatureBYTE*in
cbSignerInfoCountersignatureDWORDin
pciCountersignerCERT_INFO*in

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL CryptMsgVerifyCountersignatureEncoded(
    HCRYPTPROV_LEGACY hCryptProv,   // optional
    DWORD dwEncodingType,
    BYTE* pbSignerInfo,
    DWORD cbSignerInfo,
    BYTE* pbSignerInfoCountersignature,
    DWORD cbSignerInfoCountersignature,
    CERT_INFO* pciCountersigner
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CryptMsgVerifyCountersignatureEncoded(
    UIntPtr hCryptProv,   // HCRYPTPROV_LEGACY optional
    uint dwEncodingType,   // DWORD
    IntPtr pbSignerInfo,   // BYTE*
    uint cbSignerInfo,   // DWORD
    IntPtr pbSignerInfoCountersignature,   // BYTE*
    uint cbSignerInfoCountersignature,   // DWORD
    IntPtr pciCountersigner   // CERT_INFO*
);
<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CryptMsgVerifyCountersignatureEncoded(
    hCryptProv As UIntPtr,   ' HCRYPTPROV_LEGACY optional
    dwEncodingType As UInteger,   ' DWORD
    pbSignerInfo As IntPtr,   ' BYTE*
    cbSignerInfo As UInteger,   ' DWORD
    pbSignerInfoCountersignature As IntPtr,   ' BYTE*
    cbSignerInfoCountersignature As UInteger,   ' DWORD
    pciCountersigner As IntPtr   ' CERT_INFO*
) As Boolean
End Function
' hCryptProv : HCRYPTPROV_LEGACY optional
' dwEncodingType : DWORD
' pbSignerInfo : BYTE*
' cbSignerInfo : DWORD
' pbSignerInfoCountersignature : BYTE*
' cbSignerInfoCountersignature : DWORD
' pciCountersigner : CERT_INFO*
Declare PtrSafe Function CryptMsgVerifyCountersignatureEncoded Lib "crypt32" ( _
    ByVal hCryptProv As LongPtr, _
    ByVal dwEncodingType As Long, _
    ByVal pbSignerInfo As LongPtr, _
    ByVal cbSignerInfo As Long, _
    ByVal pbSignerInfoCountersignature As LongPtr, _
    ByVal cbSignerInfoCountersignature As Long, _
    ByVal pciCountersigner As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CryptMsgVerifyCountersignatureEncoded = ctypes.windll.crypt32.CryptMsgVerifyCountersignatureEncoded
CryptMsgVerifyCountersignatureEncoded.restype = wintypes.BOOL
CryptMsgVerifyCountersignatureEncoded.argtypes = [
    ctypes.c_size_t,  # hCryptProv : HCRYPTPROV_LEGACY optional
    wintypes.DWORD,  # dwEncodingType : DWORD
    ctypes.POINTER(ctypes.c_ubyte),  # pbSignerInfo : BYTE*
    wintypes.DWORD,  # cbSignerInfo : DWORD
    ctypes.POINTER(ctypes.c_ubyte),  # pbSignerInfoCountersignature : BYTE*
    wintypes.DWORD,  # cbSignerInfoCountersignature : DWORD
    ctypes.c_void_p,  # pciCountersigner : CERT_INFO*
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
	procCryptMsgVerifyCountersignatureEncoded = crypt32.NewProc("CryptMsgVerifyCountersignatureEncoded")
)

// hCryptProv (HCRYPTPROV_LEGACY optional), dwEncodingType (DWORD), pbSignerInfo (BYTE*), cbSignerInfo (DWORD), pbSignerInfoCountersignature (BYTE*), cbSignerInfoCountersignature (DWORD), pciCountersigner (CERT_INFO*)
r1, _, err := procCryptMsgVerifyCountersignatureEncoded.Call(
	uintptr(hCryptProv),
	uintptr(dwEncodingType),
	uintptr(pbSignerInfo),
	uintptr(cbSignerInfo),
	uintptr(pbSignerInfoCountersignature),
	uintptr(cbSignerInfoCountersignature),
	uintptr(pciCountersigner),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function CryptMsgVerifyCountersignatureEncoded(
  hCryptProv: NativeUInt;   // HCRYPTPROV_LEGACY optional
  dwEncodingType: DWORD;   // DWORD
  pbSignerInfo: Pointer;   // BYTE*
  cbSignerInfo: DWORD;   // DWORD
  pbSignerInfoCountersignature: Pointer;   // BYTE*
  cbSignerInfoCountersignature: DWORD;   // DWORD
  pciCountersigner: Pointer   // CERT_INFO*
): BOOL; stdcall;
  external 'CRYPT32.dll' name 'CryptMsgVerifyCountersignatureEncoded';
result := DllCall("CRYPT32\CryptMsgVerifyCountersignatureEncoded"
    , "UPtr", hCryptProv   ; HCRYPTPROV_LEGACY optional
    , "UInt", dwEncodingType   ; DWORD
    , "Ptr", pbSignerInfo   ; BYTE*
    , "UInt", cbSignerInfo   ; DWORD
    , "Ptr", pbSignerInfoCountersignature   ; BYTE*
    , "UInt", cbSignerInfoCountersignature   ; DWORD
    , "Ptr", pciCountersigner   ; CERT_INFO*
    , "Int")   ; return: BOOL
●CryptMsgVerifyCountersignatureEncoded(hCryptProv, dwEncodingType, pbSignerInfo, cbSignerInfo, pbSignerInfoCountersignature, cbSignerInfoCountersignature, pciCountersigner) = DLL("CRYPT32.dll", "bool CryptMsgVerifyCountersignatureEncoded(int, dword, void*, dword, void*, dword, void*)")
# 呼び出し: CryptMsgVerifyCountersignatureEncoded(hCryptProv, dwEncodingType, pbSignerInfo, cbSignerInfo, pbSignerInfoCountersignature, cbSignerInfoCountersignature, pciCountersigner)
# hCryptProv : HCRYPTPROV_LEGACY optional -> "int"
# dwEncodingType : DWORD -> "dword"
# pbSignerInfo : BYTE* -> "void*"
# cbSignerInfo : DWORD -> "dword"
# pbSignerInfoCountersignature : BYTE* -> "void*"
# cbSignerInfoCountersignature : DWORD -> "dword"
# pciCountersigner : CERT_INFO* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。