ホーム › Security.Cryptography › NCryptDecapsulate
NCryptDecapsulate
関数暗号文から共有秘密を取り出すキーデカプセル化を行う。
シグネチャ
// ncrypt.dll
#include <windows.h>
HRESULT NCryptDecapsulate(
NCRYPT_KEY_HANDLE hKey,
BYTE* pbCipherText,
DWORD cbCipherText,
BYTE* pbSecretKey, // optional
DWORD cbSecretKey,
DWORD* pcbSecretKey,
DWORD dwFlags
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hKey | NCRYPT_KEY_HANDLE | in |
| pbCipherText | BYTE* | in |
| cbCipherText | DWORD | in |
| pbSecretKey | BYTE* | outoptional |
| cbSecretKey | DWORD | in |
| pcbSecretKey | DWORD* | out |
| dwFlags | DWORD | in |
戻り値の型: HRESULT
各言語での呼び出し定義
// ncrypt.dll
#include <windows.h>
HRESULT NCryptDecapsulate(
NCRYPT_KEY_HANDLE hKey,
BYTE* pbCipherText,
DWORD cbCipherText,
BYTE* pbSecretKey, // optional
DWORD cbSecretKey,
DWORD* pcbSecretKey,
DWORD dwFlags
);[DllImport("ncrypt.dll", ExactSpelling = true)]
static extern int NCryptDecapsulate(
UIntPtr hKey, // NCRYPT_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("ncrypt.dll", ExactSpelling:=True)>
Public Shared Function NCryptDecapsulate(
hKey As UIntPtr, ' NCRYPT_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 : NCRYPT_KEY_HANDLE
' pbCipherText : BYTE*
' cbCipherText : DWORD
' pbSecretKey : BYTE* optional, out
' cbSecretKey : DWORD
' pcbSecretKey : DWORD* out
' dwFlags : DWORD
Declare PtrSafe Function NCryptDecapsulate Lib "ncrypt" ( _
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
NCryptDecapsulate = ctypes.windll.ncrypt.NCryptDecapsulate
NCryptDecapsulate.restype = ctypes.c_int
NCryptDecapsulate.argtypes = [
ctypes.c_size_t, # hKey : NCRYPT_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('ncrypt.dll')
NCryptDecapsulate = Fiddle::Function.new(
lib['NCryptDecapsulate'],
[
Fiddle::TYPE_UINTPTR_T, # hKey : NCRYPT_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 = "ncrypt")]
extern "system" {
fn NCryptDecapsulate(
hKey: usize, // NCRYPT_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("ncrypt.dll")]
public static extern int NCryptDecapsulate(UIntPtr hKey, IntPtr pbCipherText, uint cbCipherText, IntPtr pbSecretKey, uint cbSecretKey, out uint pcbSecretKey, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ncrypt_NCryptDecapsulate' -Namespace Win32 -PassThru
# $api::NCryptDecapsulate(hKey, pbCipherText, cbCipherText, pbSecretKey, cbSecretKey, pcbSecretKey, dwFlags)#uselib "ncrypt.dll"
#func global NCryptDecapsulate "NCryptDecapsulate" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; NCryptDecapsulate hKey, varptr(pbCipherText), cbCipherText, varptr(pbSecretKey), cbSecretKey, varptr(pcbSecretKey), dwFlags ; 戻り値は stat
; hKey : NCRYPT_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 "ncrypt.dll" #cfunc global NCryptDecapsulate "NCryptDecapsulate" sptr, var, int, var, int, var, int ; res = NCryptDecapsulate(hKey, pbCipherText, cbCipherText, pbSecretKey, cbSecretKey, pcbSecretKey, dwFlags) ; hKey : NCRYPT_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 "ncrypt.dll" #cfunc global NCryptDecapsulate "NCryptDecapsulate" sptr, sptr, int, sptr, int, sptr, int ; res = NCryptDecapsulate(hKey, varptr(pbCipherText), cbCipherText, varptr(pbSecretKey), cbSecretKey, varptr(pcbSecretKey), dwFlags) ; hKey : NCRYPT_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(変数))。
出力引数:
; HRESULT NCryptDecapsulate(NCRYPT_KEY_HANDLE hKey, BYTE* pbCipherText, DWORD cbCipherText, BYTE* pbSecretKey, DWORD cbSecretKey, DWORD* pcbSecretKey, DWORD dwFlags) #uselib "ncrypt.dll" #cfunc global NCryptDecapsulate "NCryptDecapsulate" intptr, var, int, var, int, var, int ; res = NCryptDecapsulate(hKey, pbCipherText, cbCipherText, pbSecretKey, cbSecretKey, pcbSecretKey, dwFlags) ; hKey : NCRYPT_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 方式にも切替可。; HRESULT NCryptDecapsulate(NCRYPT_KEY_HANDLE hKey, BYTE* pbCipherText, DWORD cbCipherText, BYTE* pbSecretKey, DWORD cbSecretKey, DWORD* pcbSecretKey, DWORD dwFlags) #uselib "ncrypt.dll" #cfunc global NCryptDecapsulate "NCryptDecapsulate" intptr, intptr, int, intptr, int, intptr, int ; res = NCryptDecapsulate(hKey, varptr(pbCipherText), cbCipherText, varptr(pbSecretKey), cbSecretKey, varptr(pcbSecretKey), dwFlags) ; hKey : NCRYPT_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 (
ncrypt = windows.NewLazySystemDLL("ncrypt.dll")
procNCryptDecapsulate = ncrypt.NewProc("NCryptDecapsulate")
)
// hKey (NCRYPT_KEY_HANDLE), pbCipherText (BYTE*), cbCipherText (DWORD), pbSecretKey (BYTE* optional, out), cbSecretKey (DWORD), pcbSecretKey (DWORD* out), dwFlags (DWORD)
r1, _, err := procNCryptDecapsulate.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 // HRESULTfunction NCryptDecapsulate(
hKey: NativeUInt; // NCRYPT_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 'ncrypt.dll' name 'NCryptDecapsulate';result := DllCall("ncrypt\NCryptDecapsulate"
, "UPtr", hKey ; NCRYPT_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: HRESULT●NCryptDecapsulate(hKey, pbCipherText, cbCipherText, pbSecretKey, cbSecretKey, pcbSecretKey, dwFlags) = DLL("ncrypt.dll", "int NCryptDecapsulate(int, void*, dword, void*, dword, void*, dword)")
# 呼び出し: NCryptDecapsulate(hKey, pbCipherText, cbCipherText, pbSecretKey, cbSecretKey, pcbSecretKey, dwFlags)
# hKey : NCRYPT_KEY_HANDLE -> "int"
# 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)。