CryptMsgGetParam
関数シグネチャ
// CRYPT32.dll
#include <windows.h>
BOOL CryptMsgGetParam(
void* hCryptMsg,
DWORD dwParamType,
DWORD dwIndex,
void* pvData, // optional
DWORD* pcbData
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hCryptMsg | void* | in | 暗号化メッセージのハンドル。 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dwParamType | DWORD | in | 取得するデータのパラメーター型を示します。取得するデータの型によって、pvData に使用する構造体の型が決まります。 エンコードされたメッセージの場合、dwParamType として有効なのは CMSG_BARE_CONTENT、CMSG_ENCODE_SIGNER、CMSG_CONTENT_PARAM、CMSG_COMPUTED_HASH_PARAM のみです。
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dwIndex | DWORD | in | 該当する場合に、取得するパラメーターのインデックス。パラメーターを取得しない場合、このパラメーターは無視され、ゼロに設定されます。 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pvData | void* | outoptional | 取得したデータを受け取るバッファーへのポインター。このデータの形式は、dwParamType パラメーターの値によって異なります。 このパラメーターは NULL にすることができ、メモリ割り当てのためにこの情報のサイズを設定する目的で使用します。詳細については、 長さが不明なデータの取得を参照してください。 このバッファーに返されたデータを処理する際、アプリケーションは返されたデータの実際のサイズを使用する必要があります。実際のサイズは、入力時に指定されたバッファーのサイズよりわずかに小さくなる場合があります。(入力時には、出力可能な最大データがバッファーに収まるように、通常はバッファーサイズが十分大きく指定されます。) 出力時には、このパラメーターが指す変数が、バッファーにコピーされたデータの実際のサイズを反映するように更新されます。 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pcbData | DWORD* | inout | pvData パラメーターが指すバッファーのサイズ (バイト単位) を指定する変数へのポインター。関数が戻るとき、pcbData パラメーターが指す変数には、バッファーに格納されたバイト数が含まれます。 |
戻り値の型: BOOL
公式ドキュメント
暗号化メッセージがエンコードまたはデコードされた後に、メッセージのパラメーターを取得します。
戻り値
関数が成功した場合、戻り値は 0 以外 (TRUE) です。
関数が失敗した場合、戻り値は 0 (FALSE) です。拡張エラー情報を取得するには、 GetLastError を呼び出します。
次の表は、GetLastError 関数によって最も一般的に返されるエラーコードの一覧です。
| 戻り値コード | 説明 |
|---|---|
| メッセージに要求された属性が含まれていません。 | |
| インデックス値が無効です。 | |
| メッセージ型が無効です。 | |
| メッセージコンテンツがまだ復号されていません。 | |
| オブジェクト識別子の形式が不正です。 | |
| メッセージが期待どおりにエンコードされていません。 | |
| 1 つ以上の引数が無効です。 | |
| 指定されたバッファーが、返されるデータを保持するのに十分な大きさではありません。 |
dwParamType が CMSG_COMPUTED_HASH_PARAM の場合、 CryptGetHashParam からエラーが伝播されることがあります。
関数が失敗した場合、GetLastError は Abstract Syntax Notation One (ASN.1) のエンコード/デコードエラーを返すことがあります。これらのエラーの詳細については、 ASN.1 エンコード/デコードの戻り値を参照してください。
解説(Remarks)
dwParamType を CMSG_VERSION_PARAM に設定して CryptMsgGetParam を呼び出すと返される、次のバージョン番号が定義されています。
- CMSG_SIGNED_DATA_V1
- CMSG_SIGNED_DATA_V3
- CMSG_SIGNED_DATA_PKCS_1_5_VERSION
- CMSG_SIGNED_DATA_CMS_VERSION
- CMSG_SIGNER_INFO_V1
- CMSG_SIGNER_INFO_V3
- CMSG_SIGNER_INFO_PKCS_1_5_VERSION
- CMSG_SIGNER_INFO_CMS_VERSION
- CMSG_HASHED_DATA_V0
- CMSG_HASHED_DATA_V2
- CMSG_HASHED_DATA_PKCS_1_5_VERSION
- CMSG_HASHED_DATA_CMS_VERSION
- CMSG_ENVELOPED_DATA_V0
- CMSG_ENVELOPED_DATA_V2
- CMSG_ENVELOPED_DATA_PKCS_1_5_VERSION
- CMSG_ENVELOPED_DATA_CMS_VERSION
例
この関数を使用する例については、 C プログラムの例: メッセージの署名、エンコード、デコード、検証、 エンベロープメッセージをエンコードする代替コード、 C プログラムの例: エンベロープされた署名付きメッセージのエンコード、および C プログラムの例: ハッシュ付きメッセージのエンコードとデコードを参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// CRYPT32.dll
#include <windows.h>
BOOL CryptMsgGetParam(
void* hCryptMsg,
DWORD dwParamType,
DWORD dwIndex,
void* pvData, // optional
DWORD* pcbData
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CryptMsgGetParam(
IntPtr hCryptMsg, // void*
uint dwParamType, // DWORD
uint dwIndex, // DWORD
IntPtr pvData, // void* optional, out
ref uint pcbData // DWORD* in/out
);<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CryptMsgGetParam(
hCryptMsg As IntPtr, ' void*
dwParamType As UInteger, ' DWORD
dwIndex As UInteger, ' DWORD
pvData As IntPtr, ' void* optional, out
ByRef pcbData As UInteger ' DWORD* in/out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hCryptMsg : void*
' dwParamType : DWORD
' dwIndex : DWORD
' pvData : void* optional, out
' pcbData : DWORD* in/out
Declare PtrSafe Function CryptMsgGetParam Lib "crypt32" ( _
ByVal hCryptMsg As LongPtr, _
ByVal dwParamType As Long, _
ByVal dwIndex As Long, _
ByVal pvData As LongPtr, _
ByRef pcbData As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CryptMsgGetParam = ctypes.windll.crypt32.CryptMsgGetParam
CryptMsgGetParam.restype = wintypes.BOOL
CryptMsgGetParam.argtypes = [
ctypes.POINTER(None), # hCryptMsg : void*
wintypes.DWORD, # dwParamType : DWORD
wintypes.DWORD, # dwIndex : DWORD
ctypes.POINTER(None), # pvData : void* optional, out
ctypes.POINTER(wintypes.DWORD), # pcbData : DWORD* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('CRYPT32.dll')
CryptMsgGetParam = Fiddle::Function.new(
lib['CryptMsgGetParam'],
[
Fiddle::TYPE_VOIDP, # hCryptMsg : void*
-Fiddle::TYPE_INT, # dwParamType : DWORD
-Fiddle::TYPE_INT, # dwIndex : DWORD
Fiddle::TYPE_VOIDP, # pvData : void* optional, out
Fiddle::TYPE_VOIDP, # pcbData : DWORD* in/out
],
Fiddle::TYPE_INT)#[link(name = "crypt32")]
extern "system" {
fn CryptMsgGetParam(
hCryptMsg: *mut (), // void*
dwParamType: u32, // DWORD
dwIndex: u32, // DWORD
pvData: *mut (), // void* optional, out
pcbData: *mut u32 // DWORD* 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 CryptMsgGetParam(IntPtr hCryptMsg, uint dwParamType, uint dwIndex, IntPtr pvData, ref uint pcbData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CryptMsgGetParam' -Namespace Win32 -PassThru
# $api::CryptMsgGetParam(hCryptMsg, dwParamType, dwIndex, pvData, pcbData)#uselib "CRYPT32.dll"
#func global CryptMsgGetParam "CryptMsgGetParam" sptr, sptr, sptr, sptr, sptr
; CryptMsgGetParam hCryptMsg, dwParamType, dwIndex, pvData, varptr(pcbData) ; 戻り値は stat
; hCryptMsg : void* -> "sptr"
; dwParamType : DWORD -> "sptr"
; dwIndex : DWORD -> "sptr"
; pvData : void* optional, out -> "sptr"
; pcbData : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "CRYPT32.dll" #cfunc global CryptMsgGetParam "CryptMsgGetParam" sptr, int, int, sptr, var ; res = CryptMsgGetParam(hCryptMsg, dwParamType, dwIndex, pvData, pcbData) ; hCryptMsg : void* -> "sptr" ; dwParamType : DWORD -> "int" ; dwIndex : DWORD -> "int" ; pvData : void* optional, out -> "sptr" ; pcbData : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "CRYPT32.dll" #cfunc global CryptMsgGetParam "CryptMsgGetParam" sptr, int, int, sptr, sptr ; res = CryptMsgGetParam(hCryptMsg, dwParamType, dwIndex, pvData, varptr(pcbData)) ; hCryptMsg : void* -> "sptr" ; dwParamType : DWORD -> "int" ; dwIndex : DWORD -> "int" ; pvData : void* optional, out -> "sptr" ; pcbData : DWORD* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; BOOL CryptMsgGetParam(void* hCryptMsg, DWORD dwParamType, DWORD dwIndex, void* pvData, DWORD* pcbData) #uselib "CRYPT32.dll" #cfunc global CryptMsgGetParam "CryptMsgGetParam" intptr, int, int, intptr, var ; res = CryptMsgGetParam(hCryptMsg, dwParamType, dwIndex, pvData, pcbData) ; hCryptMsg : void* -> "intptr" ; dwParamType : DWORD -> "int" ; dwIndex : DWORD -> "int" ; pvData : void* optional, out -> "intptr" ; pcbData : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL CryptMsgGetParam(void* hCryptMsg, DWORD dwParamType, DWORD dwIndex, void* pvData, DWORD* pcbData) #uselib "CRYPT32.dll" #cfunc global CryptMsgGetParam "CryptMsgGetParam" intptr, int, int, intptr, intptr ; res = CryptMsgGetParam(hCryptMsg, dwParamType, dwIndex, pvData, varptr(pcbData)) ; hCryptMsg : void* -> "intptr" ; dwParamType : DWORD -> "int" ; dwIndex : DWORD -> "int" ; pvData : void* optional, out -> "intptr" ; pcbData : DWORD* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
procCryptMsgGetParam = crypt32.NewProc("CryptMsgGetParam")
)
// hCryptMsg (void*), dwParamType (DWORD), dwIndex (DWORD), pvData (void* optional, out), pcbData (DWORD* in/out)
r1, _, err := procCryptMsgGetParam.Call(
uintptr(hCryptMsg),
uintptr(dwParamType),
uintptr(dwIndex),
uintptr(pvData),
uintptr(pcbData),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CryptMsgGetParam(
hCryptMsg: Pointer; // void*
dwParamType: DWORD; // DWORD
dwIndex: DWORD; // DWORD
pvData: Pointer; // void* optional, out
pcbData: Pointer // DWORD* in/out
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CryptMsgGetParam';result := DllCall("CRYPT32\CryptMsgGetParam"
, "Ptr", hCryptMsg ; void*
, "UInt", dwParamType ; DWORD
, "UInt", dwIndex ; DWORD
, "Ptr", pvData ; void* optional, out
, "Ptr", pcbData ; DWORD* in/out
, "Int") ; return: BOOL●CryptMsgGetParam(hCryptMsg, dwParamType, dwIndex, pvData, pcbData) = DLL("CRYPT32.dll", "bool CryptMsgGetParam(void*, dword, dword, void*, void*)")
# 呼び出し: CryptMsgGetParam(hCryptMsg, dwParamType, dwIndex, pvData, pcbData)
# hCryptMsg : void* -> "void*"
# dwParamType : DWORD -> "dword"
# dwIndex : DWORD -> "dword"
# pvData : void* optional, out -> "void*"
# pcbData : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "crypt32" fn CryptMsgGetParam(
hCryptMsg: ?*anyopaque, // void*
dwParamType: u32, // DWORD
dwIndex: u32, // DWORD
pvData: ?*anyopaque, // void* optional, out
pcbData: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) i32;proc CryptMsgGetParam(
hCryptMsg: pointer, # void*
dwParamType: uint32, # DWORD
dwIndex: uint32, # DWORD
pvData: pointer, # void* optional, out
pcbData: ptr uint32 # DWORD* in/out
): int32 {.importc: "CryptMsgGetParam", stdcall, dynlib: "CRYPT32.dll".}pragma(lib, "crypt32");
extern(Windows)
int CryptMsgGetParam(
void* hCryptMsg, // void*
uint dwParamType, // DWORD
uint dwIndex, // DWORD
void* pvData, // void* optional, out
uint* pcbData // DWORD* in/out
);ccall((:CryptMsgGetParam, "CRYPT32.dll"), stdcall, Int32,
(Ptr{Cvoid}, UInt32, UInt32, Ptr{Cvoid}, Ptr{UInt32}),
hCryptMsg, dwParamType, dwIndex, pvData, pcbData)
# hCryptMsg : void* -> Ptr{Cvoid}
# dwParamType : DWORD -> UInt32
# dwIndex : DWORD -> UInt32
# pvData : void* optional, out -> Ptr{Cvoid}
# pcbData : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t CryptMsgGetParam(
void* hCryptMsg,
uint32_t dwParamType,
uint32_t dwIndex,
void* pvData,
uint32_t* pcbData);
]]
local crypt32 = ffi.load("crypt32")
-- crypt32.CryptMsgGetParam(hCryptMsg, dwParamType, dwIndex, pvData, pcbData)
-- hCryptMsg : void*
-- dwParamType : DWORD
-- dwIndex : DWORD
-- pvData : void* optional, out
-- pcbData : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('CRYPT32.dll');
const CryptMsgGetParam = lib.func('__stdcall', 'CryptMsgGetParam', 'int32_t', ['void *', 'uint32_t', 'uint32_t', 'void *', 'uint32_t *']);
// CryptMsgGetParam(hCryptMsg, dwParamType, dwIndex, pvData, pcbData)
// hCryptMsg : void* -> 'void *'
// dwParamType : DWORD -> 'uint32_t'
// dwIndex : DWORD -> 'uint32_t'
// pvData : void* optional, out -> 'void *'
// pcbData : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("CRYPT32.dll", {
CryptMsgGetParam: { parameters: ["pointer", "u32", "u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.CryptMsgGetParam(hCryptMsg, dwParamType, dwIndex, pvData, pcbData)
// hCryptMsg : void* -> "pointer"
// dwParamType : DWORD -> "u32"
// dwIndex : DWORD -> "u32"
// pvData : void* optional, out -> "pointer"
// pcbData : DWORD* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CryptMsgGetParam(
void* hCryptMsg,
uint32_t dwParamType,
uint32_t dwIndex,
void* pvData,
uint32_t* pcbData);
C, "CRYPT32.dll");
// $ffi->CryptMsgGetParam(hCryptMsg, dwParamType, dwIndex, pvData, pcbData);
// hCryptMsg : void*
// dwParamType : DWORD
// dwIndex : DWORD
// pvData : void* optional, out
// pcbData : DWORD* in/out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Crypt32 extends StdCallLibrary {
Crypt32 INSTANCE = Native.load("crypt32", Crypt32.class);
boolean CryptMsgGetParam(
Pointer hCryptMsg, // void*
int dwParamType, // DWORD
int dwIndex, // DWORD
Pointer pvData, // void* optional, out
IntByReference pcbData // DWORD* in/out
);
}@[Link("crypt32")]
lib LibCRYPT32
fun CryptMsgGetParam = CryptMsgGetParam(
hCryptMsg : Void*, # void*
dwParamType : UInt32, # DWORD
dwIndex : UInt32, # DWORD
pvData : Void*, # void* optional, out
pcbData : UInt32* # DWORD* in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CryptMsgGetParamNative = Int32 Function(Pointer<Void>, Uint32, Uint32, Pointer<Void>, Pointer<Uint32>);
typedef CryptMsgGetParamDart = int Function(Pointer<Void>, int, int, Pointer<Void>, Pointer<Uint32>);
final CryptMsgGetParam = DynamicLibrary.open('CRYPT32.dll')
.lookupFunction<CryptMsgGetParamNative, CryptMsgGetParamDart>('CryptMsgGetParam');
// hCryptMsg : void* -> Pointer<Void>
// dwParamType : DWORD -> Uint32
// dwIndex : DWORD -> Uint32
// pvData : void* optional, out -> Pointer<Void>
// pcbData : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CryptMsgGetParam(
hCryptMsg: Pointer; // void*
dwParamType: DWORD; // DWORD
dwIndex: DWORD; // DWORD
pvData: Pointer; // void* optional, out
pcbData: Pointer // DWORD* in/out
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CryptMsgGetParam';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CryptMsgGetParam"
c_CryptMsgGetParam :: Ptr () -> Word32 -> Word32 -> Ptr () -> Ptr Word32 -> IO CInt
-- hCryptMsg : void* -> Ptr ()
-- dwParamType : DWORD -> Word32
-- dwIndex : DWORD -> Word32
-- pvData : void* optional, out -> Ptr ()
-- pcbData : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let cryptmsggetparam =
foreign "CryptMsgGetParam"
((ptr void) @-> uint32_t @-> uint32_t @-> (ptr void) @-> (ptr uint32_t) @-> returning int32_t)
(* hCryptMsg : void* -> (ptr void) *)
(* dwParamType : DWORD -> uint32_t *)
(* dwIndex : DWORD -> uint32_t *)
(* pvData : void* optional, out -> (ptr void) *)
(* pcbData : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library crypt32 (t "CRYPT32.dll"))
(cffi:use-foreign-library crypt32)
(cffi:defcfun ("CryptMsgGetParam" crypt-msg-get-param :convention :stdcall) :int32
(h-crypt-msg :pointer) ; void*
(dw-param-type :uint32) ; DWORD
(dw-index :uint32) ; DWORD
(pv-data :pointer) ; void* optional, out
(pcb-data :pointer)) ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CryptMsgGetParam = Win32::API::More->new('CRYPT32',
'BOOL CryptMsgGetParam(LPVOID hCryptMsg, DWORD dwParamType, DWORD dwIndex, LPVOID pvData, LPVOID pcbData)');
# my $ret = $CryptMsgGetParam->Call($hCryptMsg, $dwParamType, $dwIndex, $pvData, $pcbData);
# hCryptMsg : void* -> LPVOID
# dwParamType : DWORD -> DWORD
# dwIndex : DWORD -> DWORD
# pvData : void* optional, out -> LPVOID
# pcbData : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f CryptMsgOpenToDecode — デコード用の暗号メッセージを開く。
- f CryptMsgOpenToEncode — エンコード用の暗号メッセージ(PKCS#7/CMS)を開く。
- f CryptMsgUpdate — 暗号メッセージにデータを追加して処理を更新する。