ホーム › Security.Cryptography › BCryptDecapsulate
BCryptDecapsulate
関数秘密鍵を用いて暗号文から共有秘密を取り出す。
シグネチャ
// bcrypt.dll
#include <windows.h>
NTSTATUS BCryptDecapsulate(
BCRYPT_KEY_HANDLE hKey,
BYTE* pbCipherText,
DWORD cbCipherText,
BYTE* pbSecretKey, // optional
DWORD cbSecretKey,
DWORD* pcbSecretKey,
DWORD dwFlags
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hKey | BCRYPT_KEY_HANDLE | in |
| pbCipherText | BYTE* | in |
| cbCipherText | DWORD | in |
| pbSecretKey | BYTE* | outoptional |
| cbSecretKey | DWORD | in |
| pcbSecretKey | DWORD* | out |
| dwFlags | DWORD | in |
戻り値の型: NTSTATUS
各言語での呼び出し定義
// bcrypt.dll
#include <windows.h>
NTSTATUS BCryptDecapsulate(
BCRYPT_KEY_HANDLE hKey,
BYTE* pbCipherText,
DWORD cbCipherText,
BYTE* pbSecretKey, // optional
DWORD cbSecretKey,
DWORD* pcbSecretKey,
DWORD dwFlags
);[DllImport("bcrypt.dll", ExactSpelling = true)]
static extern int BCryptDecapsulate(
IntPtr hKey, // BCRYPT_KEY_HANDLE
IntPtr pbCipherText, // BYTE*
uint cbCipherText, // DWORD
IntPtr pbSecretKey, // BYTE* optional, out
uint cbSecretKey, // DWORD
out uint pcbSecretKey, // DWORD* out
uint dwFlags // DWORD
);<DllImport("bcrypt.dll", ExactSpelling:=True)>
Public Shared Function BCryptDecapsulate(
hKey As IntPtr, ' BCRYPT_KEY_HANDLE
pbCipherText As IntPtr, ' BYTE*
cbCipherText As UInteger, ' DWORD
pbSecretKey As IntPtr, ' BYTE* optional, out
cbSecretKey As UInteger, ' DWORD
<Out> ByRef pcbSecretKey As UInteger, ' DWORD* out
dwFlags As UInteger ' DWORD
) As Integer
End Function' hKey : BCRYPT_KEY_HANDLE
' pbCipherText : BYTE*
' cbCipherText : DWORD
' pbSecretKey : BYTE* optional, out
' cbSecretKey : DWORD
' pcbSecretKey : DWORD* out
' dwFlags : DWORD
Declare PtrSafe Function BCryptDecapsulate Lib "bcrypt" ( _
ByVal hKey As LongPtr, _
ByVal pbCipherText As LongPtr, _
ByVal cbCipherText As Long, _
ByVal pbSecretKey As LongPtr, _
ByVal cbSecretKey As Long, _
ByRef pcbSecretKey As Long, _
ByVal dwFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
BCryptDecapsulate = ctypes.windll.bcrypt.BCryptDecapsulate
BCryptDecapsulate.restype = ctypes.c_int
BCryptDecapsulate.argtypes = [
wintypes.HANDLE, # hKey : BCRYPT_KEY_HANDLE
ctypes.POINTER(ctypes.c_ubyte), # pbCipherText : BYTE*
wintypes.DWORD, # cbCipherText : DWORD
ctypes.POINTER(ctypes.c_ubyte), # pbSecretKey : BYTE* optional, out
wintypes.DWORD, # cbSecretKey : DWORD
ctypes.POINTER(wintypes.DWORD), # pcbSecretKey : DWORD* out
wintypes.DWORD, # dwFlags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('bcrypt.dll')
BCryptDecapsulate = Fiddle::Function.new(
lib['BCryptDecapsulate'],
[
Fiddle::TYPE_VOIDP, # hKey : BCRYPT_KEY_HANDLE
Fiddle::TYPE_VOIDP, # pbCipherText : BYTE*
-Fiddle::TYPE_INT, # cbCipherText : DWORD
Fiddle::TYPE_VOIDP, # pbSecretKey : BYTE* optional, out
-Fiddle::TYPE_INT, # cbSecretKey : DWORD
Fiddle::TYPE_VOIDP, # pcbSecretKey : DWORD* out
-Fiddle::TYPE_INT, # dwFlags : DWORD
],
Fiddle::TYPE_INT)#[link(name = "bcrypt")]
extern "system" {
fn BCryptDecapsulate(
hKey: *mut core::ffi::c_void, // BCRYPT_KEY_HANDLE
pbCipherText: *mut u8, // BYTE*
cbCipherText: u32, // DWORD
pbSecretKey: *mut u8, // BYTE* optional, out
cbSecretKey: u32, // DWORD
pcbSecretKey: *mut u32, // DWORD* out
dwFlags: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("bcrypt.dll")]
public static extern int BCryptDecapsulate(IntPtr hKey, IntPtr pbCipherText, uint cbCipherText, IntPtr pbSecretKey, uint cbSecretKey, out uint pcbSecretKey, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'bcrypt_BCryptDecapsulate' -Namespace Win32 -PassThru
# $api::BCryptDecapsulate(hKey, pbCipherText, cbCipherText, pbSecretKey, cbSecretKey, pcbSecretKey, dwFlags)#uselib "bcrypt.dll"
#func global BCryptDecapsulate "BCryptDecapsulate" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; BCryptDecapsulate hKey, varptr(pbCipherText), cbCipherText, varptr(pbSecretKey), cbSecretKey, varptr(pcbSecretKey), dwFlags ; 戻り値は stat
; hKey : BCRYPT_KEY_HANDLE -> "sptr"
; pbCipherText : BYTE* -> "sptr"
; cbCipherText : DWORD -> "sptr"
; pbSecretKey : BYTE* optional, out -> "sptr"
; cbSecretKey : DWORD -> "sptr"
; pcbSecretKey : DWORD* out -> "sptr"
; dwFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "bcrypt.dll" #cfunc global BCryptDecapsulate "BCryptDecapsulate" sptr, var, int, var, int, var, int ; res = BCryptDecapsulate(hKey, pbCipherText, cbCipherText, pbSecretKey, cbSecretKey, pcbSecretKey, dwFlags) ; hKey : BCRYPT_KEY_HANDLE -> "sptr" ; pbCipherText : BYTE* -> "var" ; cbCipherText : DWORD -> "int" ; pbSecretKey : BYTE* optional, out -> "var" ; cbSecretKey : DWORD -> "int" ; pcbSecretKey : DWORD* out -> "var" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "bcrypt.dll" #cfunc global BCryptDecapsulate "BCryptDecapsulate" sptr, sptr, int, sptr, int, sptr, int ; res = BCryptDecapsulate(hKey, varptr(pbCipherText), cbCipherText, varptr(pbSecretKey), cbSecretKey, varptr(pcbSecretKey), dwFlags) ; hKey : BCRYPT_KEY_HANDLE -> "sptr" ; pbCipherText : BYTE* -> "sptr" ; cbCipherText : DWORD -> "int" ; pbSecretKey : BYTE* optional, out -> "sptr" ; cbSecretKey : DWORD -> "int" ; pcbSecretKey : DWORD* out -> "sptr" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; NTSTATUS BCryptDecapsulate(BCRYPT_KEY_HANDLE hKey, BYTE* pbCipherText, DWORD cbCipherText, BYTE* pbSecretKey, DWORD cbSecretKey, DWORD* pcbSecretKey, DWORD dwFlags) #uselib "bcrypt.dll" #cfunc global BCryptDecapsulate "BCryptDecapsulate" intptr, var, int, var, int, var, int ; res = BCryptDecapsulate(hKey, pbCipherText, cbCipherText, pbSecretKey, cbSecretKey, pcbSecretKey, dwFlags) ; hKey : BCRYPT_KEY_HANDLE -> "intptr" ; pbCipherText : BYTE* -> "var" ; cbCipherText : DWORD -> "int" ; pbSecretKey : BYTE* optional, out -> "var" ; cbSecretKey : DWORD -> "int" ; pcbSecretKey : DWORD* out -> "var" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; NTSTATUS BCryptDecapsulate(BCRYPT_KEY_HANDLE hKey, BYTE* pbCipherText, DWORD cbCipherText, BYTE* pbSecretKey, DWORD cbSecretKey, DWORD* pcbSecretKey, DWORD dwFlags) #uselib "bcrypt.dll" #cfunc global BCryptDecapsulate "BCryptDecapsulate" intptr, intptr, int, intptr, int, intptr, int ; res = BCryptDecapsulate(hKey, varptr(pbCipherText), cbCipherText, varptr(pbSecretKey), cbSecretKey, varptr(pcbSecretKey), dwFlags) ; hKey : BCRYPT_KEY_HANDLE -> "intptr" ; pbCipherText : BYTE* -> "intptr" ; cbCipherText : DWORD -> "int" ; pbSecretKey : BYTE* optional, out -> "intptr" ; cbSecretKey : DWORD -> "int" ; pcbSecretKey : DWORD* out -> "intptr" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
bcrypt = windows.NewLazySystemDLL("bcrypt.dll")
procBCryptDecapsulate = bcrypt.NewProc("BCryptDecapsulate")
)
// hKey (BCRYPT_KEY_HANDLE), pbCipherText (BYTE*), cbCipherText (DWORD), pbSecretKey (BYTE* optional, out), cbSecretKey (DWORD), pcbSecretKey (DWORD* out), dwFlags (DWORD)
r1, _, err := procBCryptDecapsulate.Call(
uintptr(hKey),
uintptr(pbCipherText),
uintptr(cbCipherText),
uintptr(pbSecretKey),
uintptr(cbSecretKey),
uintptr(pcbSecretKey),
uintptr(dwFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // NTSTATUSfunction BCryptDecapsulate(
hKey: THandle; // BCRYPT_KEY_HANDLE
pbCipherText: Pointer; // BYTE*
cbCipherText: DWORD; // DWORD
pbSecretKey: Pointer; // BYTE* optional, out
cbSecretKey: DWORD; // DWORD
pcbSecretKey: Pointer; // DWORD* out
dwFlags: DWORD // DWORD
): Integer; stdcall;
external 'bcrypt.dll' name 'BCryptDecapsulate';result := DllCall("bcrypt\BCryptDecapsulate"
, "Ptr", hKey ; BCRYPT_KEY_HANDLE
, "Ptr", pbCipherText ; BYTE*
, "UInt", cbCipherText ; DWORD
, "Ptr", pbSecretKey ; BYTE* optional, out
, "UInt", cbSecretKey ; DWORD
, "Ptr", pcbSecretKey ; DWORD* out
, "UInt", dwFlags ; DWORD
, "Int") ; return: NTSTATUS●BCryptDecapsulate(hKey, pbCipherText, cbCipherText, pbSecretKey, cbSecretKey, pcbSecretKey, dwFlags) = DLL("bcrypt.dll", "int BCryptDecapsulate(void*, void*, dword, void*, dword, void*, dword)")
# 呼び出し: BCryptDecapsulate(hKey, pbCipherText, cbCipherText, pbSecretKey, cbSecretKey, pcbSecretKey, dwFlags)
# hKey : BCRYPT_KEY_HANDLE -> "void*"
# pbCipherText : BYTE* -> "void*"
# cbCipherText : DWORD -> "dword"
# pbSecretKey : BYTE* optional, out -> "void*"
# cbSecretKey : DWORD -> "dword"
# pcbSecretKey : DWORD* out -> "void*"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。