ホーム › Security.Cryptography › CryptMsgOpenToEncode
CryptMsgOpenToEncode
関数エンコード用の暗号メッセージ(PKCS#7/CMS)を開く。
シグネチャ
// CRYPT32.dll
#include <windows.h>
void* CryptMsgOpenToEncode(
DWORD dwMsgEncodingType,
DWORD dwFlags,
CRYPT_MSG_TYPE dwMsgType,
const void* pvMsgEncodeInfo,
LPSTR pszInnerContentObjID, // optional
CMSG_STREAM_INFO* pStreamInfo // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| dwMsgEncodingType | DWORD | in |
| dwFlags | DWORD | in |
| dwMsgType | CRYPT_MSG_TYPE | in |
| pvMsgEncodeInfo | void* | in |
| pszInnerContentObjID | LPSTR | inoptional |
| pStreamInfo | CMSG_STREAM_INFO* | inoptional |
戻り値の型: void*
各言語での呼び出し定義
// CRYPT32.dll
#include <windows.h>
void* CryptMsgOpenToEncode(
DWORD dwMsgEncodingType,
DWORD dwFlags,
CRYPT_MSG_TYPE dwMsgType,
const void* pvMsgEncodeInfo,
LPSTR pszInnerContentObjID, // optional
CMSG_STREAM_INFO* pStreamInfo // optional
);[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr CryptMsgOpenToEncode(
uint dwMsgEncodingType, // DWORD
uint dwFlags, // DWORD
uint dwMsgType, // CRYPT_MSG_TYPE
IntPtr pvMsgEncodeInfo, // void*
[MarshalAs(UnmanagedType.LPStr)] string pszInnerContentObjID, // LPSTR optional
IntPtr pStreamInfo // CMSG_STREAM_INFO* optional
);<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CryptMsgOpenToEncode(
dwMsgEncodingType As UInteger, ' DWORD
dwFlags As UInteger, ' DWORD
dwMsgType As UInteger, ' CRYPT_MSG_TYPE
pvMsgEncodeInfo As IntPtr, ' void*
<MarshalAs(UnmanagedType.LPStr)> pszInnerContentObjID As String, ' LPSTR optional
pStreamInfo As IntPtr ' CMSG_STREAM_INFO* optional
) As IntPtr
End Function' dwMsgEncodingType : DWORD
' dwFlags : DWORD
' dwMsgType : CRYPT_MSG_TYPE
' pvMsgEncodeInfo : void*
' pszInnerContentObjID : LPSTR optional
' pStreamInfo : CMSG_STREAM_INFO* optional
Declare PtrSafe Function CryptMsgOpenToEncode Lib "crypt32" ( _
ByVal dwMsgEncodingType As Long, _
ByVal dwFlags As Long, _
ByVal dwMsgType As Long, _
ByVal pvMsgEncodeInfo As LongPtr, _
ByVal pszInnerContentObjID As String, _
ByVal pStreamInfo As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CryptMsgOpenToEncode = ctypes.windll.crypt32.CryptMsgOpenToEncode
CryptMsgOpenToEncode.restype = ctypes.c_void_p
CryptMsgOpenToEncode.argtypes = [
wintypes.DWORD, # dwMsgEncodingType : DWORD
wintypes.DWORD, # dwFlags : DWORD
wintypes.DWORD, # dwMsgType : CRYPT_MSG_TYPE
ctypes.POINTER(None), # pvMsgEncodeInfo : void*
wintypes.LPCSTR, # pszInnerContentObjID : LPSTR 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')
CryptMsgOpenToEncode = Fiddle::Function.new(
lib['CryptMsgOpenToEncode'],
[
-Fiddle::TYPE_INT, # dwMsgEncodingType : DWORD
-Fiddle::TYPE_INT, # dwFlags : DWORD
-Fiddle::TYPE_INT, # dwMsgType : CRYPT_MSG_TYPE
Fiddle::TYPE_VOIDP, # pvMsgEncodeInfo : void*
Fiddle::TYPE_VOIDP, # pszInnerContentObjID : LPSTR optional
Fiddle::TYPE_VOIDP, # pStreamInfo : CMSG_STREAM_INFO* optional
],
Fiddle::TYPE_VOIDP)#[link(name = "crypt32")]
extern "system" {
fn CryptMsgOpenToEncode(
dwMsgEncodingType: u32, // DWORD
dwFlags: u32, // DWORD
dwMsgType: u32, // CRYPT_MSG_TYPE
pvMsgEncodeInfo: *const (), // void*
pszInnerContentObjID: *mut u8, // LPSTR 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 CryptMsgOpenToEncode(uint dwMsgEncodingType, uint dwFlags, uint dwMsgType, IntPtr pvMsgEncodeInfo, [MarshalAs(UnmanagedType.LPStr)] string pszInnerContentObjID, IntPtr pStreamInfo);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CryptMsgOpenToEncode' -Namespace Win32 -PassThru
# $api::CryptMsgOpenToEncode(dwMsgEncodingType, dwFlags, dwMsgType, pvMsgEncodeInfo, pszInnerContentObjID, pStreamInfo)#uselib "CRYPT32.dll"
#func global CryptMsgOpenToEncode "CryptMsgOpenToEncode" sptr, sptr, sptr, sptr, sptr, sptr
; CryptMsgOpenToEncode dwMsgEncodingType, dwFlags, dwMsgType, pvMsgEncodeInfo, pszInnerContentObjID, varptr(pStreamInfo) ; 戻り値は stat
; dwMsgEncodingType : DWORD -> "sptr"
; dwFlags : DWORD -> "sptr"
; dwMsgType : CRYPT_MSG_TYPE -> "sptr"
; pvMsgEncodeInfo : void* -> "sptr"
; pszInnerContentObjID : LPSTR optional -> "sptr"
; pStreamInfo : CMSG_STREAM_INFO* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "CRYPT32.dll" #cfunc global CryptMsgOpenToEncode "CryptMsgOpenToEncode" int, int, int, sptr, str, var ; res = CryptMsgOpenToEncode(dwMsgEncodingType, dwFlags, dwMsgType, pvMsgEncodeInfo, pszInnerContentObjID, pStreamInfo) ; dwMsgEncodingType : DWORD -> "int" ; dwFlags : DWORD -> "int" ; dwMsgType : CRYPT_MSG_TYPE -> "int" ; pvMsgEncodeInfo : void* -> "sptr" ; pszInnerContentObjID : LPSTR optional -> "str" ; pStreamInfo : CMSG_STREAM_INFO* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "CRYPT32.dll" #cfunc global CryptMsgOpenToEncode "CryptMsgOpenToEncode" int, int, int, sptr, str, sptr ; res = CryptMsgOpenToEncode(dwMsgEncodingType, dwFlags, dwMsgType, pvMsgEncodeInfo, pszInnerContentObjID, varptr(pStreamInfo)) ; dwMsgEncodingType : DWORD -> "int" ; dwFlags : DWORD -> "int" ; dwMsgType : CRYPT_MSG_TYPE -> "int" ; pvMsgEncodeInfo : void* -> "sptr" ; pszInnerContentObjID : LPSTR optional -> "str" ; pStreamInfo : CMSG_STREAM_INFO* optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; void* CryptMsgOpenToEncode(DWORD dwMsgEncodingType, DWORD dwFlags, CRYPT_MSG_TYPE dwMsgType, void* pvMsgEncodeInfo, LPSTR pszInnerContentObjID, CMSG_STREAM_INFO* pStreamInfo) #uselib "CRYPT32.dll" #cfunc global CryptMsgOpenToEncode "CryptMsgOpenToEncode" int, int, int, intptr, str, var ; res = CryptMsgOpenToEncode(dwMsgEncodingType, dwFlags, dwMsgType, pvMsgEncodeInfo, pszInnerContentObjID, pStreamInfo) ; dwMsgEncodingType : DWORD -> "int" ; dwFlags : DWORD -> "int" ; dwMsgType : CRYPT_MSG_TYPE -> "int" ; pvMsgEncodeInfo : void* -> "intptr" ; pszInnerContentObjID : LPSTR optional -> "str" ; pStreamInfo : CMSG_STREAM_INFO* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; void* CryptMsgOpenToEncode(DWORD dwMsgEncodingType, DWORD dwFlags, CRYPT_MSG_TYPE dwMsgType, void* pvMsgEncodeInfo, LPSTR pszInnerContentObjID, CMSG_STREAM_INFO* pStreamInfo) #uselib "CRYPT32.dll" #cfunc global CryptMsgOpenToEncode "CryptMsgOpenToEncode" int, int, int, intptr, str, intptr ; res = CryptMsgOpenToEncode(dwMsgEncodingType, dwFlags, dwMsgType, pvMsgEncodeInfo, pszInnerContentObjID, varptr(pStreamInfo)) ; dwMsgEncodingType : DWORD -> "int" ; dwFlags : DWORD -> "int" ; dwMsgType : CRYPT_MSG_TYPE -> "int" ; pvMsgEncodeInfo : void* -> "intptr" ; pszInnerContentObjID : LPSTR optional -> "str" ; pStreamInfo : CMSG_STREAM_INFO* optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
procCryptMsgOpenToEncode = crypt32.NewProc("CryptMsgOpenToEncode")
)
// dwMsgEncodingType (DWORD), dwFlags (DWORD), dwMsgType (CRYPT_MSG_TYPE), pvMsgEncodeInfo (void*), pszInnerContentObjID (LPSTR optional), pStreamInfo (CMSG_STREAM_INFO* optional)
r1, _, err := procCryptMsgOpenToEncode.Call(
uintptr(dwMsgEncodingType),
uintptr(dwFlags),
uintptr(dwMsgType),
uintptr(pvMsgEncodeInfo),
uintptr(unsafe.Pointer(windows.BytePtrFromString(pszInnerContentObjID))),
uintptr(pStreamInfo),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // void*function CryptMsgOpenToEncode(
dwMsgEncodingType: DWORD; // DWORD
dwFlags: DWORD; // DWORD
dwMsgType: DWORD; // CRYPT_MSG_TYPE
pvMsgEncodeInfo: Pointer; // void*
pszInnerContentObjID: PAnsiChar; // LPSTR optional
pStreamInfo: Pointer // CMSG_STREAM_INFO* optional
): Pointer; stdcall;
external 'CRYPT32.dll' name 'CryptMsgOpenToEncode';result := DllCall("CRYPT32\CryptMsgOpenToEncode"
, "UInt", dwMsgEncodingType ; DWORD
, "UInt", dwFlags ; DWORD
, "UInt", dwMsgType ; CRYPT_MSG_TYPE
, "Ptr", pvMsgEncodeInfo ; void*
, "AStr", pszInnerContentObjID ; LPSTR optional
, "Ptr", pStreamInfo ; CMSG_STREAM_INFO* optional
, "Ptr") ; return: void*●CryptMsgOpenToEncode(dwMsgEncodingType, dwFlags, dwMsgType, pvMsgEncodeInfo, pszInnerContentObjID, pStreamInfo) = DLL("CRYPT32.dll", "void* CryptMsgOpenToEncode(dword, dword, dword, void*, char*, void*)")
# 呼び出し: CryptMsgOpenToEncode(dwMsgEncodingType, dwFlags, dwMsgType, pvMsgEncodeInfo, pszInnerContentObjID, pStreamInfo)
# dwMsgEncodingType : DWORD -> "dword"
# dwFlags : DWORD -> "dword"
# dwMsgType : CRYPT_MSG_TYPE -> "dword"
# pvMsgEncodeInfo : void* -> "void*"
# pszInnerContentObjID : LPSTR optional -> "char*"
# pStreamInfo : CMSG_STREAM_INFO* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。