ホーム › Security.Cryptography › CMSG_CNG_CONTENT_DECRYPT_INFO
CMSG_CNG_CONTENT_DECRYPT_INFO
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 |
|---|---|---|---|---|---|
| cbSize | DWORD | 4 | +0 | +0 | この構造体のサイズ(バイト単位)。 |
| ContentEncryptionAlgorithm | CRYPT_ALGORITHM_IDENTIFIER | 24/12 | +8 | +4 | コンテンツ暗号化に使われたアルゴリズム識別子。 |
| pfnAlloc | PFN_CMSG_ALLOC | 8/4 | +32 | +16 | メモリ確保に使うコールバック関数へのポインタ。 |
| pfnFree | PFN_CMSG_FREE | 8/4 | +40 | +20 | メモリ解放に使うコールバック関数へのポインタ。 |
| hNCryptKey | NCRYPT_KEY_HANDLE | 8/4 | +48 | +24 | 復号に使うNCrypt鍵ハンドル。 |
| pbContentEncryptKey | BYTE* | 8/4 | +56 | +28 | 復号されたコンテンツ暗号鍵のバイト列へのポインタ。 |
| cbContentEncryptKey | DWORD | 4 | +64 | +32 | pbContentEncryptKeyのサイズ(バイト単位)。 |
| hCNGContentEncryptKey | BCRYPT_KEY_HANDLE | 8/4 | +72 | +36 | 復号に使うCNG(BCrypt)コンテンツ暗号鍵ハンドル。 |
| pbCNGContentEncryptKeyObject | BYTE* | 8/4 | +80 | +40 | CNGコンテンツ暗号鍵オブジェクトを格納するバッファへのポインタ。 |
各言語での定義
#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_CNG_CONTENT_DECRYPT_INFO (x64 88 / x86 44 バイト)
typedef struct CMSG_CNG_CONTENT_DECRYPT_INFO {
DWORD cbSize;
CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
PFN_CMSG_ALLOC pfnAlloc;
PFN_CMSG_FREE pfnFree;
NCRYPT_KEY_HANDLE hNCryptKey;
BYTE* pbContentEncryptKey;
DWORD cbContentEncryptKey;
BCRYPT_KEY_HANDLE hCNGContentEncryptKey;
BYTE* pbCNGContentEncryptKeyObject;
} CMSG_CNG_CONTENT_DECRYPT_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_CNG_CONTENT_DECRYPT_INFO
{
public uint cbSize;
public CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
public IntPtr pfnAlloc;
public IntPtr pfnFree;
public UIntPtr hNCryptKey;
public IntPtr pbContentEncryptKey;
public uint cbContentEncryptKey;
public IntPtr hCNGContentEncryptKey;
public IntPtr pbCNGContentEncryptKeyObject;
}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_CNG_CONTENT_DECRYPT_INFO
Public cbSize As UInteger
Public ContentEncryptionAlgorithm As CRYPT_ALGORITHM_IDENTIFIER
Public pfnAlloc As IntPtr
Public pfnFree As IntPtr
Public hNCryptKey As UIntPtr
Public pbContentEncryptKey As IntPtr
Public cbContentEncryptKey As UInteger
Public hCNGContentEncryptKey As IntPtr
Public pbCNGContentEncryptKeyObject 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_CNG_CONTENT_DECRYPT_INFO(ctypes.Structure):
_fields_ = [
("cbSize", wintypes.DWORD),
("ContentEncryptionAlgorithm", CRYPT_ALGORITHM_IDENTIFIER),
("pfnAlloc", ctypes.c_void_p),
("pfnFree", ctypes.c_void_p),
("hNCryptKey", ctypes.c_size_t),
("pbContentEncryptKey", ctypes.c_void_p),
("cbContentEncryptKey", wintypes.DWORD),
("hCNGContentEncryptKey", ctypes.c_void_p),
("pbCNGContentEncryptKeyObject", 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_CNG_CONTENT_DECRYPT_INFO {
pub cbSize: u32,
pub ContentEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER,
pub pfnAlloc: *mut core::ffi::c_void,
pub pfnFree: *mut core::ffi::c_void,
pub hNCryptKey: usize,
pub pbContentEncryptKey: *mut core::ffi::c_void,
pub cbContentEncryptKey: u32,
pub hCNGContentEncryptKey: *mut core::ffi::c_void,
pub pbCNGContentEncryptKeyObject: *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_CNG_CONTENT_DECRYPT_INFO struct {
cbSize uint32
ContentEncryptionAlgorithm CRYPT_ALGORITHM_IDENTIFIER
pfnAlloc uintptr
pfnFree uintptr
hNCryptKey uintptr
pbContentEncryptKey uintptr
cbContentEncryptKey uint32
hCNGContentEncryptKey uintptr
pbCNGContentEncryptKeyObject uintptr
}type
CRYPT_INTEGER_BLOB = record
cbData: DWORD;
pbData: Pointer;
end;
CRYPT_ALGORITHM_IDENTIFIER = record
pszObjId: Pointer;
Parameters: CRYPT_INTEGER_BLOB;
end;
CMSG_CNG_CONTENT_DECRYPT_INFO = record
cbSize: DWORD;
ContentEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
pfnAlloc: Pointer;
pfnFree: Pointer;
hNCryptKey: NativeUInt;
pbContentEncryptKey: Pointer;
cbContentEncryptKey: DWORD;
hCNGContentEncryptKey: Pointer;
pbCNGContentEncryptKeyObject: 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_CNG_CONTENT_DECRYPT_INFO = extern struct {
cbSize: u32,
ContentEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER,
pfnAlloc: ?*anyopaque,
pfnFree: ?*anyopaque,
hNCryptKey: usize,
pbContentEncryptKey: ?*anyopaque,
cbContentEncryptKey: u32,
hCNGContentEncryptKey: ?*anyopaque,
pbCNGContentEncryptKeyObject: ?*anyopaque,
};type
CRYPT_INTEGER_BLOB {.bycopy.} = object
cbData: uint32
pbData: pointer
CRYPT_ALGORITHM_IDENTIFIER {.bycopy.} = object
pszObjId: pointer
Parameters: CRYPT_INTEGER_BLOB
CMSG_CNG_CONTENT_DECRYPT_INFO {.bycopy.} = object
cbSize: uint32
ContentEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER
pfnAlloc: pointer
pfnFree: pointer
hNCryptKey: uint
pbContentEncryptKey: pointer
cbContentEncryptKey: uint32
hCNGContentEncryptKey: pointer
pbCNGContentEncryptKeyObject: pointerstruct CRYPT_INTEGER_BLOB
{
uint cbData;
void* pbData;
}
struct CRYPT_ALGORITHM_IDENTIFIER
{
void* pszObjId;
CRYPT_INTEGER_BLOB Parameters;
}
struct CMSG_CNG_CONTENT_DECRYPT_INFO
{
uint cbSize;
CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
void* pfnAlloc;
void* pfnFree;
size_t hNCryptKey;
void* pbContentEncryptKey;
uint cbContentEncryptKey;
void* hCNGContentEncryptKey;
void* pbCNGContentEncryptKeyObject;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; CMSG_CNG_CONTENT_DECRYPT_INFO サイズ: 44 バイト(x86)
dim st, 11 ; 4byte整数×11(構造体サイズ 44 / 4 切り上げ)
; cbSize : DWORD (+0, 4byte) st.0 = 値 / 値 = st.0 (lpoke/lpeek も可)
; ContentEncryptionAlgorithm : CRYPT_ALGORITHM_IDENTIFIER (+4, 12byte) varptr(st)+4 を基点に操作(12byte:入れ子/配列)
; pfnAlloc : PFN_CMSG_ALLOC (+16, 4byte) st.4 = 値 / 値 = st.4 (lpoke/lpeek も可)
; pfnFree : PFN_CMSG_FREE (+20, 4byte) st.5 = 値 / 値 = st.5 (lpoke/lpeek も可)
; hNCryptKey : NCRYPT_KEY_HANDLE (+24, 4byte) st.6 = 値 / 値 = st.6 (lpoke/lpeek も可)
; pbContentEncryptKey : BYTE* (+28, 4byte) st.7 = 値 / 値 = st.7 (lpoke/lpeek も可)
; cbContentEncryptKey : DWORD (+32, 4byte) st.8 = 値 / 値 = st.8 (lpoke/lpeek も可)
; hCNGContentEncryptKey : BCRYPT_KEY_HANDLE (+36, 4byte) st.9 = 値 / 値 = st.9 (lpoke/lpeek も可)
; pbCNGContentEncryptKeyObject : BYTE* (+40, 4byte) st.10 = 値 / 値 = st.10 (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; CMSG_CNG_CONTENT_DECRYPT_INFO サイズ: 88 バイト(x64)
dim st, 22 ; 4byte整数×22(構造体サイズ 88 / 4 切り上げ)
; cbSize : DWORD (+0, 4byte) st.0 = 値 / 値 = st.0 (lpoke/lpeek も可)
; ContentEncryptionAlgorithm : CRYPT_ALGORITHM_IDENTIFIER (+8, 24byte) varptr(st)+8 を基点に操作(24byte:入れ子/配列)
; pfnAlloc : PFN_CMSG_ALLOC (+32, 8byte) qpoke st,32,値 / qpeek(st,32) ※IronHSPのみ。3.7/3.8は lpoke st,32,下位 : lpoke st,36,上位
; pfnFree : PFN_CMSG_FREE (+40, 8byte) qpoke st,40,値 / qpeek(st,40) ※IronHSPのみ。3.7/3.8は lpoke st,40,下位 : lpoke st,44,上位
; hNCryptKey : NCRYPT_KEY_HANDLE (+48, 8byte) qpoke st,48,値 / qpeek(st,48) ※IronHSPのみ。3.7/3.8は lpoke st,48,下位 : lpoke st,52,上位
; pbContentEncryptKey : BYTE* (+56, 8byte) qpoke st,56,値 / qpeek(st,56) ※IronHSPのみ。3.7/3.8は lpoke st,56,下位 : lpoke st,60,上位
; cbContentEncryptKey : DWORD (+64, 4byte) st.16 = 値 / 値 = st.16 (lpoke/lpeek も可)
; hCNGContentEncryptKey : BCRYPT_KEY_HANDLE (+72, 8byte) qpoke st,72,値 / qpeek(st,72) ※IronHSPのみ。3.7/3.8は lpoke st,72,下位 : lpoke st,76,上位
; pbCNGContentEncryptKeyObject : BYTE* (+80, 8byte) qpoke st,80,値 / qpeek(st,80) ※IronHSPのみ。3.7/3.8は lpoke st,80,下位 : lpoke st,84,上位
; ※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_CNG_CONTENT_DECRYPT_INFO
#field int cbSize
#field CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm
#field intptr pfnAlloc
#field intptr pfnFree
#field intptr hNCryptKey
#field intptr pbContentEncryptKey
#field int cbContentEncryptKey
#field intptr hCNGContentEncryptKey
#field intptr pbCNGContentEncryptKeyObject
#endstruct
stdim st, CMSG_CNG_CONTENT_DECRYPT_INFO ; NSTRUCT 変数を確保
st->cbSize = 100
mes "cbSize=" + st->cbSize