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

CryptMsgOpenToDecode

関数
デコード用の暗号メッセージを開く。
DLLCRYPT32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

void* CryptMsgOpenToDecode(
    DWORD dwMsgEncodingType,
    DWORD dwFlags,
    DWORD dwMsgType,
    HCRYPTPROV_LEGACY hCryptProv,   // optional
    CERT_INFO* pRecipientInfo,   // optional
    CMSG_STREAM_INFO* pStreamInfo   // optional
);

パラメーター

名前方向
dwMsgEncodingTypeDWORDin
dwFlagsDWORDin
dwMsgTypeDWORDin
hCryptProvHCRYPTPROV_LEGACYinoptional
pRecipientInfoCERT_INFO*optional
pStreamInfoCMSG_STREAM_INFO*inoptional

戻り値の型: void*

各言語での呼び出し定義

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

void* CryptMsgOpenToDecode(
    DWORD dwMsgEncodingType,
    DWORD dwFlags,
    DWORD dwMsgType,
    HCRYPTPROV_LEGACY hCryptProv,   // optional
    CERT_INFO* pRecipientInfo,   // optional
    CMSG_STREAM_INFO* pStreamInfo   // optional
);
[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr CryptMsgOpenToDecode(
    uint dwMsgEncodingType,   // DWORD
    uint dwFlags,   // DWORD
    uint dwMsgType,   // DWORD
    UIntPtr hCryptProv,   // HCRYPTPROV_LEGACY optional
    IntPtr pRecipientInfo,   // CERT_INFO* optional
    IntPtr pStreamInfo   // CMSG_STREAM_INFO* optional
);
<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CryptMsgOpenToDecode(
    dwMsgEncodingType As UInteger,   ' DWORD
    dwFlags As UInteger,   ' DWORD
    dwMsgType As UInteger,   ' DWORD
    hCryptProv As UIntPtr,   ' HCRYPTPROV_LEGACY optional
    pRecipientInfo As IntPtr,   ' CERT_INFO* optional
    pStreamInfo As IntPtr   ' CMSG_STREAM_INFO* optional
) As IntPtr
End Function
' dwMsgEncodingType : DWORD
' dwFlags : DWORD
' dwMsgType : DWORD
' hCryptProv : HCRYPTPROV_LEGACY optional
' pRecipientInfo : CERT_INFO* optional
' pStreamInfo : CMSG_STREAM_INFO* optional
Declare PtrSafe Function CryptMsgOpenToDecode Lib "crypt32" ( _
    ByVal dwMsgEncodingType As Long, _
    ByVal dwFlags As Long, _
    ByVal dwMsgType As Long, _
    ByVal hCryptProv As LongPtr, _
    ByVal pRecipientInfo As LongPtr, _
    ByVal pStreamInfo As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CryptMsgOpenToDecode = ctypes.windll.crypt32.CryptMsgOpenToDecode
CryptMsgOpenToDecode.restype = ctypes.c_void_p
CryptMsgOpenToDecode.argtypes = [
    wintypes.DWORD,  # dwMsgEncodingType : DWORD
    wintypes.DWORD,  # dwFlags : DWORD
    wintypes.DWORD,  # dwMsgType : DWORD
    ctypes.c_size_t,  # hCryptProv : HCRYPTPROV_LEGACY optional
    ctypes.c_void_p,  # pRecipientInfo : CERT_INFO* optional
    ctypes.c_void_p,  # pStreamInfo : CMSG_STREAM_INFO* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('CRYPT32.dll')
CryptMsgOpenToDecode = Fiddle::Function.new(
  lib['CryptMsgOpenToDecode'],
  [
    -Fiddle::TYPE_INT,  # dwMsgEncodingType : DWORD
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
    -Fiddle::TYPE_INT,  # dwMsgType : DWORD
    Fiddle::TYPE_UINTPTR_T,  # hCryptProv : HCRYPTPROV_LEGACY optional
    Fiddle::TYPE_VOIDP,  # pRecipientInfo : CERT_INFO* optional
    Fiddle::TYPE_VOIDP,  # pStreamInfo : CMSG_STREAM_INFO* optional
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "crypt32")]
extern "system" {
    fn CryptMsgOpenToDecode(
        dwMsgEncodingType: u32,  // DWORD
        dwFlags: u32,  // DWORD
        dwMsgType: u32,  // DWORD
        hCryptProv: usize,  // HCRYPTPROV_LEGACY optional
        pRecipientInfo: *mut CERT_INFO,  // CERT_INFO* optional
        pStreamInfo: *mut CMSG_STREAM_INFO  // CMSG_STREAM_INFO* optional
    ) -> *mut ();
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("CRYPT32.dll", SetLastError = true)]
public static extern IntPtr CryptMsgOpenToDecode(uint dwMsgEncodingType, uint dwFlags, uint dwMsgType, UIntPtr hCryptProv, IntPtr pRecipientInfo, IntPtr pStreamInfo);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CryptMsgOpenToDecode' -Namespace Win32 -PassThru
# $api::CryptMsgOpenToDecode(dwMsgEncodingType, dwFlags, dwMsgType, hCryptProv, pRecipientInfo, pStreamInfo)
#uselib "CRYPT32.dll"
#func global CryptMsgOpenToDecode "CryptMsgOpenToDecode" sptr, sptr, sptr, sptr, sptr, sptr
; CryptMsgOpenToDecode dwMsgEncodingType, dwFlags, dwMsgType, hCryptProv, varptr(pRecipientInfo), varptr(pStreamInfo)   ; 戻り値は stat
; dwMsgEncodingType : DWORD -> "sptr"
; dwFlags : DWORD -> "sptr"
; dwMsgType : DWORD -> "sptr"
; hCryptProv : HCRYPTPROV_LEGACY optional -> "sptr"
; pRecipientInfo : CERT_INFO* optional -> "sptr"
; pStreamInfo : CMSG_STREAM_INFO* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "CRYPT32.dll"
#cfunc global CryptMsgOpenToDecode "CryptMsgOpenToDecode" int, int, int, sptr, var, var
; res = CryptMsgOpenToDecode(dwMsgEncodingType, dwFlags, dwMsgType, hCryptProv, pRecipientInfo, pStreamInfo)
; dwMsgEncodingType : DWORD -> "int"
; dwFlags : DWORD -> "int"
; dwMsgType : DWORD -> "int"
; hCryptProv : HCRYPTPROV_LEGACY optional -> "sptr"
; pRecipientInfo : CERT_INFO* optional -> "var"
; pStreamInfo : CMSG_STREAM_INFO* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; void* CryptMsgOpenToDecode(DWORD dwMsgEncodingType, DWORD dwFlags, DWORD dwMsgType, HCRYPTPROV_LEGACY hCryptProv, CERT_INFO* pRecipientInfo, CMSG_STREAM_INFO* pStreamInfo)
#uselib "CRYPT32.dll"
#cfunc global CryptMsgOpenToDecode "CryptMsgOpenToDecode" int, int, int, intptr, var, var
; res = CryptMsgOpenToDecode(dwMsgEncodingType, dwFlags, dwMsgType, hCryptProv, pRecipientInfo, pStreamInfo)
; dwMsgEncodingType : DWORD -> "int"
; dwFlags : DWORD -> "int"
; dwMsgType : DWORD -> "int"
; hCryptProv : HCRYPTPROV_LEGACY optional -> "intptr"
; pRecipientInfo : CERT_INFO* optional -> "var"
; pStreamInfo : CMSG_STREAM_INFO* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
	procCryptMsgOpenToDecode = crypt32.NewProc("CryptMsgOpenToDecode")
)

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