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

CMSG_CONTENT_ENCRYPT_INFO

構造体
サイズx64: 128 バイト / x86: 68 バイト

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
cbSizeDWORD4+0+0この構造体のサイズ(バイト単位)。
hCryptProvHCRYPTPROV_LEGACY8/4+8+4コンテンツ暗号化に使うレガシーCSPハンドル。0でも可。
ContentEncryptionAlgorithmCRYPT_ALGORITHM_IDENTIFIER24/12+16+8コンテンツ暗号化に使うアルゴリズム識別子。
pvEncryptionAuxInfovoid*8/4+40+20暗号化アルゴリズムの補助情報へのポインタ。NULL可。
cRecipientsDWORD4+48+24rgCmsRecipients配列の要素数。
rgCmsRecipientsCMSG_RECIPIENT_ENCODE_INFO*8/4+56+28CMS受信者エンコード情報の配列へのポインタ。
pfnAllocPFN_CMSG_ALLOC8/4+64+32メモリ確保に使うコールバック関数へのポインタ。
pfnFreePFN_CMSG_FREE8/4+72+36メモリ解放に使うコールバック関数へのポインタ。
dwEncryptFlagsDWORD4+80+40暗号化動作を制御するフラグ。
Anonymous_Anonymous_e__Union8/4+88+44暗号鍵ハンドルなどを保持する共用体。
dwFlagsDWORD4+96+48この構造体の付加的な動作フラグ。
fCNGBOOL4+100+52CNG(Cryptography Next Generation)を使うかを示すブール値。
pbCNGContentEncryptKeyObjectBYTE*8/4+104+56CNGコンテンツ暗号鍵オブジェクトを格納するバッファへのポインタ。
pbContentEncryptKeyBYTE*8/4+112+60コンテンツ暗号鍵のバイト列へのポインタ。
cbContentEncryptKeyDWORD4+120+64pbContentEncryptKeyのサイズ(バイト単位)。

共用体: _Anonymous_e__Union x64 8B / x86 4B

フィールドサイズx64x86
hContentEncryptKeyUINT_PTR8/4+0+0
hCNGContentEncryptKeyBCRYPT_KEY_HANDLE8/4+0+0

各言語での定義

#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_CONTENT_ENCRYPT_INFO  (x64 128 / x86 68 バイト)
typedef struct CMSG_CONTENT_ENCRYPT_INFO {
    DWORD cbSize;
    HCRYPTPROV_LEGACY hCryptProv;
    CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
    void* pvEncryptionAuxInfo;
    DWORD cRecipients;
    CMSG_RECIPIENT_ENCODE_INFO* rgCmsRecipients;
    PFN_CMSG_ALLOC pfnAlloc;
    PFN_CMSG_FREE pfnFree;
    DWORD dwEncryptFlags;
    _Anonymous_e__Union Anonymous;
    DWORD dwFlags;
    BOOL fCNG;
    BYTE* pbCNGContentEncryptKeyObject;
    BYTE* pbContentEncryptKey;
    DWORD cbContentEncryptKey;
} CMSG_CONTENT_ENCRYPT_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_CONTENT_ENCRYPT_INFO
{
    public uint cbSize;
    public UIntPtr hCryptProv;
    public CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
    public IntPtr pvEncryptionAuxInfo;
    public uint cRecipients;
    public IntPtr rgCmsRecipients;
    public IntPtr pfnAlloc;
    public IntPtr pfnFree;
    public uint dwEncryptFlags;
    public _Anonymous_e__Union Anonymous;
    public uint dwFlags;
    [MarshalAs(UnmanagedType.Bool)] public bool fCNG;
    public IntPtr pbCNGContentEncryptKeyObject;
    public IntPtr pbContentEncryptKey;
    public uint cbContentEncryptKey;
}
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_CONTENT_ENCRYPT_INFO
    Public cbSize As UInteger
    Public hCryptProv As UIntPtr
    Public ContentEncryptionAlgorithm As CRYPT_ALGORITHM_IDENTIFIER
    Public pvEncryptionAuxInfo As IntPtr
    Public cRecipients As UInteger
    Public rgCmsRecipients As IntPtr
    Public pfnAlloc As IntPtr
    Public pfnFree As IntPtr
    Public dwEncryptFlags As UInteger
    Public Anonymous As _Anonymous_e__Union
    Public dwFlags As UInteger
    <MarshalAs(UnmanagedType.Bool)> Public fCNG As Boolean
    Public pbCNGContentEncryptKeyObject As IntPtr
    Public pbContentEncryptKey As IntPtr
    Public cbContentEncryptKey As UInteger
End Structure
import 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_CONTENT_ENCRYPT_INFO(ctypes.Structure):
    _fields_ = [
        ("cbSize", wintypes.DWORD),
        ("hCryptProv", ctypes.c_size_t),
        ("ContentEncryptionAlgorithm", CRYPT_ALGORITHM_IDENTIFIER),
        ("pvEncryptionAuxInfo", ctypes.c_void_p),
        ("cRecipients", wintypes.DWORD),
        ("rgCmsRecipients", ctypes.c_void_p),
        ("pfnAlloc", ctypes.c_void_p),
        ("pfnFree", ctypes.c_void_p),
        ("dwEncryptFlags", wintypes.DWORD),
        ("Anonymous", _Anonymous_e__Union),
        ("dwFlags", wintypes.DWORD),
        ("fCNG", wintypes.BOOL),
        ("pbCNGContentEncryptKeyObject", ctypes.c_void_p),
        ("pbContentEncryptKey", ctypes.c_void_p),
        ("cbContentEncryptKey", wintypes.DWORD),
    ]
#[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_CONTENT_ENCRYPT_INFO {
    pub cbSize: u32,
    pub hCryptProv: usize,
    pub ContentEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER,
    pub pvEncryptionAuxInfo: *mut core::ffi::c_void,
    pub cRecipients: u32,
    pub rgCmsRecipients: *mut core::ffi::c_void,
    pub pfnAlloc: *mut core::ffi::c_void,
    pub pfnFree: *mut core::ffi::c_void,
    pub dwEncryptFlags: u32,
    pub Anonymous: _Anonymous_e__Union,
    pub dwFlags: u32,
    pub fCNG: i32,
    pub pbCNGContentEncryptKeyObject: *mut core::ffi::c_void,
    pub pbContentEncryptKey: *mut core::ffi::c_void,
    pub cbContentEncryptKey: u32,
}
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_CONTENT_ENCRYPT_INFO struct {
	cbSize uint32
	hCryptProv uintptr
	ContentEncryptionAlgorithm CRYPT_ALGORITHM_IDENTIFIER
	pvEncryptionAuxInfo uintptr
	cRecipients uint32
	rgCmsRecipients uintptr
	pfnAlloc uintptr
	pfnFree uintptr
	dwEncryptFlags uint32
	Anonymous _Anonymous_e__Union
	dwFlags uint32
	fCNG int32
	pbCNGContentEncryptKeyObject uintptr
	pbContentEncryptKey uintptr
	cbContentEncryptKey uint32
}
type
  CRYPT_INTEGER_BLOB = record
    cbData: DWORD;
    pbData: Pointer;
  end;

  CRYPT_ALGORITHM_IDENTIFIER = record
    pszObjId: Pointer;
    Parameters: CRYPT_INTEGER_BLOB;
  end;

  CMSG_CONTENT_ENCRYPT_INFO = record
    cbSize: DWORD;
    hCryptProv: NativeUInt;
    ContentEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
    pvEncryptionAuxInfo: Pointer;
    cRecipients: DWORD;
    rgCmsRecipients: Pointer;
    pfnAlloc: Pointer;
    pfnFree: Pointer;
    dwEncryptFlags: DWORD;
    Anonymous: _Anonymous_e__Union;
    dwFlags: DWORD;
    fCNG: BOOL;
    pbCNGContentEncryptKeyObject: Pointer;
    pbContentEncryptKey: Pointer;
    cbContentEncryptKey: DWORD;
  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_CONTENT_ENCRYPT_INFO = extern struct {
    cbSize: u32,
    hCryptProv: usize,
    ContentEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER,
    pvEncryptionAuxInfo: ?*anyopaque,
    cRecipients: u32,
    rgCmsRecipients: ?*anyopaque,
    pfnAlloc: ?*anyopaque,
    pfnFree: ?*anyopaque,
    dwEncryptFlags: u32,
    Anonymous: _Anonymous_e__Union,
    dwFlags: u32,
    fCNG: i32,
    pbCNGContentEncryptKeyObject: ?*anyopaque,
    pbContentEncryptKey: ?*anyopaque,
    cbContentEncryptKey: u32,
};
type
  CRYPT_INTEGER_BLOB {.bycopy.} = object
    cbData: uint32
    pbData: pointer

  CRYPT_ALGORITHM_IDENTIFIER {.bycopy.} = object
    pszObjId: pointer
    Parameters: CRYPT_INTEGER_BLOB

  CMSG_CONTENT_ENCRYPT_INFO {.bycopy.} = object
    cbSize: uint32
    hCryptProv: uint
    ContentEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER
    pvEncryptionAuxInfo: pointer
    cRecipients: uint32
    rgCmsRecipients: pointer
    pfnAlloc: pointer
    pfnFree: pointer
    dwEncryptFlags: uint32
    Anonymous: _Anonymous_e__Union
    dwFlags: uint32
    fCNG: int32
    pbCNGContentEncryptKeyObject: pointer
    pbContentEncryptKey: pointer
    cbContentEncryptKey: uint32
struct CRYPT_INTEGER_BLOB
{
    uint cbData;
    void* pbData;
}

struct CRYPT_ALGORITHM_IDENTIFIER
{
    void* pszObjId;
    CRYPT_INTEGER_BLOB Parameters;
}

struct CMSG_CONTENT_ENCRYPT_INFO
{
    uint cbSize;
    size_t hCryptProv;
    CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
    void* pvEncryptionAuxInfo;
    uint cRecipients;
    void* rgCmsRecipients;
    void* pfnAlloc;
    void* pfnFree;
    uint dwEncryptFlags;
    _Anonymous_e__Union Anonymous;
    uint dwFlags;
    int fCNG;
    void* pbCNGContentEncryptKeyObject;
    void* pbContentEncryptKey;
    uint cbContentEncryptKey;
}

HSP用 定義

HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; CMSG_CONTENT_ENCRYPT_INFO サイズ: 68 バイト(x86)
dim st, 17    ; 4byte整数×17(構造体サイズ 68 / 4 切り上げ)
; cbSize : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; hCryptProv : HCRYPTPROV_LEGACY (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; ContentEncryptionAlgorithm : CRYPT_ALGORITHM_IDENTIFIER (+8, 12byte)  varptr(st)+8 を基点に操作(12byte:入れ子/配列)
; pvEncryptionAuxInfo : void* (+20, 4byte)  st.5 = 値  /  値 = st.5   (lpoke/lpeek も可)
; cRecipients : DWORD (+24, 4byte)  st.6 = 値  /  値 = st.6   (lpoke/lpeek も可)
; rgCmsRecipients : CMSG_RECIPIENT_ENCODE_INFO* (+28, 4byte)  varptr(st)+28 を基点に操作(4byte:入れ子/配列)
; pfnAlloc : PFN_CMSG_ALLOC (+32, 4byte)  st.8 = 値  /  値 = st.8   (lpoke/lpeek も可)
; pfnFree : PFN_CMSG_FREE (+36, 4byte)  st.9 = 値  /  値 = st.9   (lpoke/lpeek も可)
; dwEncryptFlags : DWORD (+40, 4byte)  st.10 = 値  /  値 = st.10   (lpoke/lpeek も可)
; Anonymous : _Anonymous_e__Union (+44, 4byte)  varptr(st)+44 を基点に操作(4byte:入れ子/配列)
; dwFlags : DWORD (+48, 4byte)  st.12 = 値  /  値 = st.12   (lpoke/lpeek も可)
; fCNG : BOOL (+52, 4byte)  st.13 = 値  /  値 = st.13   (lpoke/lpeek も可)
; pbCNGContentEncryptKeyObject : BYTE* (+56, 4byte)  st.14 = 値  /  値 = st.14   (lpoke/lpeek も可)
; pbContentEncryptKey : BYTE* (+60, 4byte)  st.15 = 値  /  値 = st.15   (lpoke/lpeek も可)
; cbContentEncryptKey : DWORD (+64, 4byte)  st.16 = 値  /  値 = st.16   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; CMSG_CONTENT_ENCRYPT_INFO サイズ: 128 バイト(x64)
dim st, 32    ; 4byte整数×32(構造体サイズ 128 / 4 切り上げ)
; cbSize : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; hCryptProv : HCRYPTPROV_LEGACY (+8, 8byte)  qpoke st,8,値 / qpeek(st,8)  ※IronHSPのみ。3.7/3.8は lpoke st,8,下位 : lpoke st,12,上位
; ContentEncryptionAlgorithm : CRYPT_ALGORITHM_IDENTIFIER (+16, 24byte)  varptr(st)+16 を基点に操作(24byte:入れ子/配列)
; pvEncryptionAuxInfo : void* (+40, 8byte)  qpoke st,40,値 / qpeek(st,40)  ※IronHSPのみ。3.7/3.8は lpoke st,40,下位 : lpoke st,44,上位
; cRecipients : DWORD (+48, 4byte)  st.12 = 値  /  値 = st.12   (lpoke/lpeek も可)
; rgCmsRecipients : CMSG_RECIPIENT_ENCODE_INFO* (+56, 8byte)  varptr(st)+56 を基点に操作(8byte:入れ子/配列)
; pfnAlloc : PFN_CMSG_ALLOC (+64, 8byte)  qpoke st,64,値 / qpeek(st,64)  ※IronHSPのみ。3.7/3.8は lpoke st,64,下位 : lpoke st,68,上位
; pfnFree : PFN_CMSG_FREE (+72, 8byte)  qpoke st,72,値 / qpeek(st,72)  ※IronHSPのみ。3.7/3.8は lpoke st,72,下位 : lpoke st,76,上位
; dwEncryptFlags : DWORD (+80, 4byte)  st.20 = 値  /  値 = st.20   (lpoke/lpeek も可)
; Anonymous : _Anonymous_e__Union (+88, 8byte)  varptr(st)+88 を基点に操作(8byte:入れ子/配列)
; dwFlags : DWORD (+96, 4byte)  st.24 = 値  /  値 = st.24   (lpoke/lpeek も可)
; fCNG : BOOL (+100, 4byte)  st.25 = 値  /  値 = st.25   (lpoke/lpeek も可)
; pbCNGContentEncryptKeyObject : BYTE* (+104, 8byte)  qpoke st,104,値 / qpeek(st,104)  ※IronHSPのみ。3.7/3.8は lpoke st,104,下位 : lpoke st,108,上位
; pbContentEncryptKey : BYTE* (+112, 8byte)  qpoke st,112,値 / qpeek(st,112)  ※IronHSPのみ。3.7/3.8は lpoke st,112,下位 : lpoke st,116,上位
; cbContentEncryptKey : DWORD (+120, 4byte)  st.30 = 値  /  値 = st.30   (lpoke/lpeek も可)
; ※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_CONTENT_ENCRYPT_INFO
    #field int cbSize
    #field intptr hCryptProv
    #field CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm
    #field intptr pvEncryptionAuxInfo
    #field int cRecipients
    #field intptr rgCmsRecipients
    #field intptr pfnAlloc
    #field intptr pfnFree
    #field int dwEncryptFlags
    #field byte Anonymous 8
    #field int dwFlags
    #field bool fCNG
    #field intptr pbCNGContentEncryptKeyObject
    #field intptr pbContentEncryptKey
    #field int cbContentEncryptKey
#endstruct

stdim st, CMSG_CONTENT_ENCRYPT_INFO        ; NSTRUCT 変数を確保
st->cbSize = 100
mes "cbSize=" + st->cbSize
; ※union フィールドは byte 列で確保(NSTRUCT は union 非対応)。必要に応じ手動でアクセス。