CMSG_SIGNER_ENCODE_INFO
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| cbSize | DWORD | 4 | +0 | +0 | この構造体のサイズ (バイト単位)。 | ||||||
| pCertInfo | CERT_INFO* | 8/4 | +8 | +4 | CERT_INFO 構造体へのポインター。この構造体には Issuer、SerialNumber、SubjectPublicKeyInfo の各メンバーが含まれます。 Issuer 構造体と SerialNumber 構造体の pbData メンバーの組み合わせによって、証明書が一意に識別されます。SubjectPublicKeyInfo 構造体の Algorithm メンバーは、使用されるハッシュ暗号化アルゴリズムを指定します。 | ||||||
| Anonymous | _Anonymous_e__Union | 8/4 | +16 | +8 | 署名に使う暗号プロバイダまたはCNG鍵ハンドルを保持する共用体。 | ||||||
| dwKeySpec | DWORD | 4 | +24 | +12 | 使用する秘密キーを指定します。このメンバーは、hNCryptKey メンバーを使用する場合には使用されません。 dwKeySpec が 0 の場合は、既定値である AT_KEYEXCHANGE が使用されます。 既定のプロバイダーに対しては、次の dwKeySpec の値が定義されています。
| ||||||
| HashAlgorithm | CRYPT_ALGORITHM_IDENTIFIER | 24/12 | +32 | +16 | ハッシュアルゴリズムを指定する CRYPT_ALGORITHM_IDENTIFIER 構造体です。 | ||||||
| pvHashAuxInfo | void* | 8/4 | +56 | +28 | 使用されません。このメンバーは NULL に設定しなければなりません。 | ||||||
| cAuthAttr | DWORD | 4 | +64 | +32 | rgAuthAttr 配列の要素数。rgAuthAttr に認証済み属性が存在しない場合、cAuthAttr は 0 です。 | ||||||
| rgAuthAttr | CRYPT_ATTRIBUTE* | 8/4 | +72 | +36 | CRYPT_ATTRIBUTE 構造体へのポインターの配列で、各構造体には認証済み属性の情報が格納されます。 PKCS #9 標準では、属性が存在する場合は少なくとも 2 つ、つまりコンテンツタイプのオブジェクト識別子 (OID) とメッセージのハッシュが必要と定められています。これらの属性はシステムによって自動的に追加されます。 | ||||||
| cUnauthAttr | DWORD | 4 | +80 | +40 | rgUnauthAttr 配列の要素数。認証されていない属性が存在しない場合、cUnauthAttr は 0 です。 | ||||||
| rgUnauthAttr | CRYPT_ATTRIBUTE* | 8/4 | +88 | +44 | CRYPT_ATTRIBUTE 構造体へのポインターの配列で、各構造体には認証されていない属性の情報が格納されます。認証されていない属性には、副署などを格納できます。 |
共用体: _Anonymous_e__Union x64 8B / x86 4B
| フィールド | 型 | サイズ | x64 | x86 | 説明 |
|---|---|---|---|---|---|
| hCryptProv | UINT_PTR | 8/4 | +0 | +0 | 暗号化サービスプロバイダー (CSP) へのハンドル。 HashEncryptionAlgorithm に szOID_PKIX_NO_SIGNATURE が設定されている場合、このハンドルには、dwFlags パラメーターに CRYPT_VERIFYCONTEXT を設定して取得した CSP のハンドルを指定できます。共用体のどちらのメンバーが使用されているかを判断するために、CNG 関数 NCryptIsKeyHandle が呼び出されます。 |
| hNCryptKey | NCRYPT_KEY_HANDLE | 8/4 | +0 | +0 | CNG CSP へのハンドル。共用体のどちらのメンバーが使用されているかを判断するために、CNG 関数 NCryptIsKeyHandle が呼び出されます。新しい暗号化アルゴリズムは CNG 関数でのみサポートされます。必要に応じて、CryptoAPI の hCryptProv を変換するために CNG 関数 NCryptTranslateHandle が呼び出されます。アプリケーションでは、NCryptOpenKey 関数から返された CNG CSP のハンドルを hNCryptKey メンバーに渡すことを推奨します。 |
公式ドキュメント
CMSG_SIGNER_ENCODE_INFO 構造体は署名者情報を格納します。この構造体は CryptMsgCountersign および CryptMsgCountersignEncoded に渡されます。また、dwMsgType パラメーターが CMSG_SIGNED の場合は、 CMSG_SIGNED_ENCODE_INFO 構造体のメンバーとして CryptMsgOpenToEncode に渡すこともできます。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での定義
#include <windows.h>
// CRYPT_INTEGER_BLOB (x64 16 / x86 8 バイト)
typedef struct CRYPT_INTEGER_BLOB {
DWORD cbData;
BYTE* pbData;
} CRYPT_INTEGER_BLOB;
// CRYPT_ALGORITHM_IDENTIFIER (x64 24 / x86 12 バイト)
typedef struct CRYPT_ALGORITHM_IDENTIFIER {
LPSTR pszObjId;
CRYPT_INTEGER_BLOB Parameters;
} CRYPT_ALGORITHM_IDENTIFIER;
// CMSG_SIGNER_ENCODE_INFO (x64 96 / x86 48 バイト)
typedef struct CMSG_SIGNER_ENCODE_INFO {
DWORD cbSize;
CERT_INFO* pCertInfo;
_Anonymous_e__Union Anonymous;
DWORD dwKeySpec;
CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
void* pvHashAuxInfo;
DWORD cAuthAttr;
CRYPT_ATTRIBUTE* rgAuthAttr;
DWORD cUnauthAttr;
CRYPT_ATTRIBUTE* rgUnauthAttr;
} CMSG_SIGNER_ENCODE_INFO;using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct CRYPT_INTEGER_BLOB
{
public uint cbData;
public IntPtr pbData;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct CRYPT_ALGORITHM_IDENTIFIER
{
public IntPtr pszObjId;
public CRYPT_INTEGER_BLOB Parameters;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct CMSG_SIGNER_ENCODE_INFO
{
public uint cbSize;
public IntPtr pCertInfo;
public _Anonymous_e__Union Anonymous;
public uint dwKeySpec;
public CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
public IntPtr pvHashAuxInfo;
public uint cAuthAttr;
public IntPtr rgAuthAttr;
public uint cUnauthAttr;
public IntPtr rgUnauthAttr;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure CRYPT_INTEGER_BLOB
Public cbData As UInteger
Public pbData As IntPtr
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure CRYPT_ALGORITHM_IDENTIFIER
Public pszObjId As IntPtr
Public Parameters As CRYPT_INTEGER_BLOB
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure CMSG_SIGNER_ENCODE_INFO
Public cbSize As UInteger
Public pCertInfo As IntPtr
Public Anonymous As _Anonymous_e__Union
Public dwKeySpec As UInteger
Public HashAlgorithm As CRYPT_ALGORITHM_IDENTIFIER
Public pvHashAuxInfo As IntPtr
Public cAuthAttr As UInteger
Public rgAuthAttr As IntPtr
Public cUnauthAttr As UInteger
Public rgUnauthAttr As IntPtr
End Structureimport ctypes
from ctypes import wintypes
class CRYPT_INTEGER_BLOB(ctypes.Structure):
_fields_ = [
("cbData", wintypes.DWORD),
("pbData", ctypes.c_void_p),
]
class CRYPT_ALGORITHM_IDENTIFIER(ctypes.Structure):
_fields_ = [
("pszObjId", ctypes.c_void_p),
("Parameters", CRYPT_INTEGER_BLOB),
]
class CMSG_SIGNER_ENCODE_INFO(ctypes.Structure):
_fields_ = [
("cbSize", wintypes.DWORD),
("pCertInfo", ctypes.c_void_p),
("Anonymous", _Anonymous_e__Union),
("dwKeySpec", wintypes.DWORD),
("HashAlgorithm", CRYPT_ALGORITHM_IDENTIFIER),
("pvHashAuxInfo", ctypes.c_void_p),
("cAuthAttr", wintypes.DWORD),
("rgAuthAttr", ctypes.c_void_p),
("cUnauthAttr", wintypes.DWORD),
("rgUnauthAttr", ctypes.c_void_p),
]#[repr(C)]
pub struct CRYPT_INTEGER_BLOB {
pub cbData: u32,
pub pbData: *mut core::ffi::c_void,
}
#[repr(C)]
pub struct CRYPT_ALGORITHM_IDENTIFIER {
pub pszObjId: *mut core::ffi::c_void,
pub Parameters: CRYPT_INTEGER_BLOB,
}
#[repr(C)]
pub struct CMSG_SIGNER_ENCODE_INFO {
pub cbSize: u32,
pub pCertInfo: *mut core::ffi::c_void,
pub Anonymous: _Anonymous_e__Union,
pub dwKeySpec: u32,
pub HashAlgorithm: CRYPT_ALGORITHM_IDENTIFIER,
pub pvHashAuxInfo: *mut core::ffi::c_void,
pub cAuthAttr: u32,
pub rgAuthAttr: *mut core::ffi::c_void,
pub cUnauthAttr: u32,
pub rgUnauthAttr: *mut core::ffi::c_void,
}import "golang.org/x/sys/windows"
type CRYPT_INTEGER_BLOB struct {
cbData uint32
pbData uintptr
}
type CRYPT_ALGORITHM_IDENTIFIER struct {
pszObjId uintptr
Parameters CRYPT_INTEGER_BLOB
}
type CMSG_SIGNER_ENCODE_INFO struct {
cbSize uint32
pCertInfo uintptr
Anonymous _Anonymous_e__Union
dwKeySpec uint32
HashAlgorithm CRYPT_ALGORITHM_IDENTIFIER
pvHashAuxInfo uintptr
cAuthAttr uint32
rgAuthAttr uintptr
cUnauthAttr uint32
rgUnauthAttr uintptr
}type
CRYPT_INTEGER_BLOB = record
cbData: DWORD;
pbData: Pointer;
end;
CRYPT_ALGORITHM_IDENTIFIER = record
pszObjId: Pointer;
Parameters: CRYPT_INTEGER_BLOB;
end;
CMSG_SIGNER_ENCODE_INFO = record
cbSize: DWORD;
pCertInfo: Pointer;
Anonymous: _Anonymous_e__Union;
dwKeySpec: DWORD;
HashAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
pvHashAuxInfo: Pointer;
cAuthAttr: DWORD;
rgAuthAttr: Pointer;
cUnauthAttr: DWORD;
rgUnauthAttr: Pointer;
end;const CRYPT_INTEGER_BLOB = extern struct {
cbData: u32,
pbData: ?*anyopaque,
};
const CRYPT_ALGORITHM_IDENTIFIER = extern struct {
pszObjId: ?*anyopaque,
Parameters: CRYPT_INTEGER_BLOB,
};
const CMSG_SIGNER_ENCODE_INFO = extern struct {
cbSize: u32,
pCertInfo: ?*anyopaque,
Anonymous: _Anonymous_e__Union,
dwKeySpec: u32,
HashAlgorithm: CRYPT_ALGORITHM_IDENTIFIER,
pvHashAuxInfo: ?*anyopaque,
cAuthAttr: u32,
rgAuthAttr: ?*anyopaque,
cUnauthAttr: u32,
rgUnauthAttr: ?*anyopaque,
};type
CRYPT_INTEGER_BLOB {.bycopy.} = object
cbData: uint32
pbData: pointer
CRYPT_ALGORITHM_IDENTIFIER {.bycopy.} = object
pszObjId: pointer
Parameters: CRYPT_INTEGER_BLOB
CMSG_SIGNER_ENCODE_INFO {.bycopy.} = object
cbSize: uint32
pCertInfo: pointer
Anonymous: _Anonymous_e__Union
dwKeySpec: uint32
HashAlgorithm: CRYPT_ALGORITHM_IDENTIFIER
pvHashAuxInfo: pointer
cAuthAttr: uint32
rgAuthAttr: pointer
cUnauthAttr: uint32
rgUnauthAttr: pointerstruct CRYPT_INTEGER_BLOB
{
uint cbData;
void* pbData;
}
struct CRYPT_ALGORITHM_IDENTIFIER
{
void* pszObjId;
CRYPT_INTEGER_BLOB Parameters;
}
struct CMSG_SIGNER_ENCODE_INFO
{
uint cbSize;
void* pCertInfo;
_Anonymous_e__Union Anonymous;
uint dwKeySpec;
CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
void* pvHashAuxInfo;
uint cAuthAttr;
void* rgAuthAttr;
uint cUnauthAttr;
void* rgUnauthAttr;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; CMSG_SIGNER_ENCODE_INFO サイズ: 48 バイト(x86)
dim st, 12 ; 4byte整数×12(構造体サイズ 48 / 4 切り上げ)
; cbSize : DWORD (+0, 4byte) st.0 = 値 / 値 = st.0 (lpoke/lpeek も可)
; pCertInfo : CERT_INFO* (+4, 4byte) varptr(st)+4 を基点に操作(4byte:入れ子/配列)
; Anonymous : _Anonymous_e__Union (+8, 4byte) varptr(st)+8 を基点に操作(4byte:入れ子/配列)
; dwKeySpec : DWORD (+12, 4byte) st.3 = 値 / 値 = st.3 (lpoke/lpeek も可)
; HashAlgorithm : CRYPT_ALGORITHM_IDENTIFIER (+16, 12byte) varptr(st)+16 を基点に操作(12byte:入れ子/配列)
; pvHashAuxInfo : void* (+28, 4byte) st.7 = 値 / 値 = st.7 (lpoke/lpeek も可)
; cAuthAttr : DWORD (+32, 4byte) st.8 = 値 / 値 = st.8 (lpoke/lpeek も可)
; rgAuthAttr : CRYPT_ATTRIBUTE* (+36, 4byte) varptr(st)+36 を基点に操作(4byte:入れ子/配列)
; cUnauthAttr : DWORD (+40, 4byte) st.10 = 値 / 値 = st.10 (lpoke/lpeek も可)
; rgUnauthAttr : CRYPT_ATTRIBUTE* (+44, 4byte) varptr(st)+44 を基点に操作(4byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; CMSG_SIGNER_ENCODE_INFO サイズ: 96 バイト(x64)
dim st, 24 ; 4byte整数×24(構造体サイズ 96 / 4 切り上げ)
; cbSize : DWORD (+0, 4byte) st.0 = 値 / 値 = st.0 (lpoke/lpeek も可)
; pCertInfo : CERT_INFO* (+8, 8byte) varptr(st)+8 を基点に操作(8byte:入れ子/配列)
; Anonymous : _Anonymous_e__Union (+16, 8byte) varptr(st)+16 を基点に操作(8byte:入れ子/配列)
; dwKeySpec : DWORD (+24, 4byte) st.6 = 値 / 値 = st.6 (lpoke/lpeek も可)
; HashAlgorithm : CRYPT_ALGORITHM_IDENTIFIER (+32, 24byte) varptr(st)+32 を基点に操作(24byte:入れ子/配列)
; pvHashAuxInfo : void* (+56, 8byte) qpoke st,56,値 / qpeek(st,56) ※IronHSPのみ。3.7/3.8は lpoke st,56,下位 : lpoke st,60,上位
; cAuthAttr : DWORD (+64, 4byte) st.16 = 値 / 値 = st.16 (lpoke/lpeek も可)
; rgAuthAttr : CRYPT_ATTRIBUTE* (+72, 8byte) varptr(st)+72 を基点に操作(8byte:入れ子/配列)
; cUnauthAttr : DWORD (+80, 4byte) st.20 = 値 / 値 = st.20 (lpoke/lpeek も可)
; rgUnauthAttr : CRYPT_ATTRIBUTE* (+88, 8byte) varptr(st)+88 を基点に操作(8byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global CRYPT_INTEGER_BLOB
#field int cbData
#field intptr pbData
#endstruct
#defstruct global CRYPT_ALGORITHM_IDENTIFIER
#field intptr pszObjId
#field CRYPT_INTEGER_BLOB Parameters
#endstruct
#defstruct global CMSG_SIGNER_ENCODE_INFO
#field int cbSize
#field intptr pCertInfo
#field byte Anonymous 8
#field int dwKeySpec
#field CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm
#field intptr pvHashAuxInfo
#field int cAuthAttr
#field intptr rgAuthAttr
#field int cUnauthAttr
#field intptr rgUnauthAttr
#endstruct
stdim st, CMSG_SIGNER_ENCODE_INFO ; NSTRUCT 変数を確保
st->cbSize = 100
mes "cbSize=" + st->cbSize
; ※union フィールドは byte 列で確保(NSTRUCT は union 非対応)。必要に応じ手動でアクセス。