BCRYPT_RSAKEY_BLOB
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Magic | BCRYPT_RSAKEY_BLOB_MAGIC | 4 | +0 | +0 | この BLOB が表す RSA キーの種類を指定します。次のいずれかの値になります。
| ||||||||
| BitLength | DWORD | 4 | +4 | +4 | キーのサイズ (ビット単位)。 | ||||||||
| cbPublicExp | DWORD | 4 | +8 | +8 | キーの指数のサイズ (バイト単位)。Windows 10 バージョン 1903 以降では、(2^64 - 1) より大きい公開指数はサポートされません。 | ||||||||
| cbModulus | DWORD | 4 | +12 | +12 | キーの法 (モジュラス) のサイズ (バイト単位)。 | ||||||||
| cbPrime1 | DWORD | 4 | +16 | +16 | キーの 1 番目の素数のサイズ (バイト単位)。これは秘密キー BLOB でのみ使用されます。 | ||||||||
| cbPrime2 | DWORD | 4 | +20 | +20 | キーの 2 番目の素数のサイズ (バイト単位)。これは秘密キー BLOB でのみ使用されます。 |
公式ドキュメント
解説(Remarks)
この構造体は、より大きなバッファーのヘッダーとして使用されます。RSA 公開キー BLOB (BCRYPT_RSAPUBLIC_BLOB) は、連続したメモリ内で次の形式になります。構造体に続く数値はすべてビッグエンディアン形式です。
BCRYPT_RSAKEY_BLOB
PublicExponent[cbPublicExp] // Big-endian.
Modulus[cbModulus] // Big-endian.
RSA 秘密キー BLOB (BCRYPT_RSAPRIVATE_BLOB) は、連続したメモリ内で次の形式になります。構造体に続く数値はすべてビッグエンディアン形式です。
BCRYPT_RSAKEY_BLOB
PublicExponent[cbPublicExp] // Big-endian.
Modulus[cbModulus] // Big-endian.
Prime1[cbPrime1] // Big-endian.
Prime2[cbPrime2] // Big-endian.
完全な RSA 秘密キー BLOB (BCRYPT_RSAFULLPRIVATE_BLOB) は、連続したメモリ内で次の形式になります。構造体に続く数値はすべてビッグエンディアン形式です。
なお、cbModulus バイト内での PrivateExponent には数学的に等価な表現が複数存在するため、Windows のバージョンによっては BCryptExportKey の呼び出しで得られる PrivateExponent の値が異なる場合があります。特に、一部のバージョンでは PrivateExponent は (Prime1 - 1) * (Prime2 - 1) を法としてエクスポートされ、別のバージョンでは LeastCommonMultiple(Prime1 - 1, Prime2 - 1) を法としてエクスポートされます。
BCRYPT_RSAKEY_BLOB
PublicExponent[cbPublicExp] // Big-endian.
Modulus[cbModulus] // Big-endian.
Prime1[cbPrime1] // Big-endian.
Prime2[cbPrime2] // Big-endian.
Exponent1[cbPrime1] // Big-endian.
Exponent2[cbPrime2] // Big-endian.
Coefficient[cbPrime1] // Big-endian.
PrivateExponent[cbModulus] // Big-endian.
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での定義
#include <windows.h>
// BCRYPT_RSAKEY_BLOB (x64 24 / x86 24 バイト)
typedef struct BCRYPT_RSAKEY_BLOB {
BCRYPT_RSAKEY_BLOB_MAGIC Magic;
DWORD BitLength;
DWORD cbPublicExp;
DWORD cbModulus;
DWORD cbPrime1;
DWORD cbPrime2;
} BCRYPT_RSAKEY_BLOB;using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct BCRYPT_RSAKEY_BLOB
{
public uint Magic;
public uint BitLength;
public uint cbPublicExp;
public uint cbModulus;
public uint cbPrime1;
public uint cbPrime2;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure BCRYPT_RSAKEY_BLOB
Public Magic As UInteger
Public BitLength As UInteger
Public cbPublicExp As UInteger
Public cbModulus As UInteger
Public cbPrime1 As UInteger
Public cbPrime2 As UInteger
End Structureimport ctypes
from ctypes import wintypes
class BCRYPT_RSAKEY_BLOB(ctypes.Structure):
_fields_ = [
("Magic", wintypes.DWORD),
("BitLength", wintypes.DWORD),
("cbPublicExp", wintypes.DWORD),
("cbModulus", wintypes.DWORD),
("cbPrime1", wintypes.DWORD),
("cbPrime2", wintypes.DWORD),
]#[repr(C)]
pub struct BCRYPT_RSAKEY_BLOB {
pub Magic: u32,
pub BitLength: u32,
pub cbPublicExp: u32,
pub cbModulus: u32,
pub cbPrime1: u32,
pub cbPrime2: u32,
}import "golang.org/x/sys/windows"
type BCRYPT_RSAKEY_BLOB struct {
Magic uint32
BitLength uint32
cbPublicExp uint32
cbModulus uint32
cbPrime1 uint32
cbPrime2 uint32
}type
BCRYPT_RSAKEY_BLOB = record
Magic: DWORD;
BitLength: DWORD;
cbPublicExp: DWORD;
cbModulus: DWORD;
cbPrime1: DWORD;
cbPrime2: DWORD;
end;const BCRYPT_RSAKEY_BLOB = extern struct {
Magic: u32,
BitLength: u32,
cbPublicExp: u32,
cbModulus: u32,
cbPrime1: u32,
cbPrime2: u32,
};type
BCRYPT_RSAKEY_BLOB {.bycopy.} = object
Magic: uint32
BitLength: uint32
cbPublicExp: uint32
cbModulus: uint32
cbPrime1: uint32
cbPrime2: uint32struct BCRYPT_RSAKEY_BLOB
{
uint Magic;
uint BitLength;
uint cbPublicExp;
uint cbModulus;
uint cbPrime1;
uint cbPrime2;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; BCRYPT_RSAKEY_BLOB サイズ: 24 バイト(x64)
dim st, 6 ; 4byte整数×6(構造体サイズ 24 / 4 切り上げ)
; Magic : BCRYPT_RSAKEY_BLOB_MAGIC (+0, 4byte) st.0 = 値 / 値 = st.0 (lpoke/lpeek も可)
; BitLength : DWORD (+4, 4byte) st.1 = 値 / 値 = st.1 (lpoke/lpeek も可)
; cbPublicExp : DWORD (+8, 4byte) st.2 = 値 / 値 = st.2 (lpoke/lpeek も可)
; cbModulus : DWORD (+12, 4byte) st.3 = 値 / 値 = st.3 (lpoke/lpeek も可)
; cbPrime1 : DWORD (+16, 4byte) st.4 = 値 / 値 = st.4 (lpoke/lpeek も可)
; cbPrime2 : DWORD (+20, 4byte) st.5 = 値 / 値 = st.5 (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global BCRYPT_RSAKEY_BLOB
#field int Magic
#field int BitLength
#field int cbPublicExp
#field int cbModulus
#field int cbPrime1
#field int cbPrime2
#endstruct
stdim st, BCRYPT_RSAKEY_BLOB ; NSTRUCT 変数を確保
st->Magic = 100
mes "Magic=" + st->Magic