ホーム › Security.Cryptography › NCryptDecrypt
NCryptDecrypt
関数指定したキーを使って暗号文を復号する。
シグネチャ
// ncrypt.dll
#include <windows.h>
HRESULT NCryptDecrypt(
NCRYPT_KEY_HANDLE hKey,
BYTE* pbInput, // optional
DWORD cbInput,
void* pPaddingInfo, // optional
BYTE* pbOutput, // optional
DWORD cbOutput,
DWORD* pcbResult,
NCRYPT_FLAGS dwFlags
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hKey | NCRYPT_KEY_HANDLE | in |
| pbInput | BYTE* | inoptional |
| cbInput | DWORD | in |
| pPaddingInfo | void* | inoptional |
| pbOutput | BYTE* | outoptional |
| cbOutput | DWORD | in |
| pcbResult | DWORD* | out |
| dwFlags | NCRYPT_FLAGS | in |
戻り値の型: HRESULT
各言語での呼び出し定義
// ncrypt.dll
#include <windows.h>
HRESULT NCryptDecrypt(
NCRYPT_KEY_HANDLE hKey,
BYTE* pbInput, // optional
DWORD cbInput,
void* pPaddingInfo, // optional
BYTE* pbOutput, // optional
DWORD cbOutput,
DWORD* pcbResult,
NCRYPT_FLAGS dwFlags
);[DllImport("ncrypt.dll", ExactSpelling = true)]
static extern int NCryptDecrypt(
UIntPtr hKey, // NCRYPT_KEY_HANDLE
IntPtr pbInput, // BYTE* optional
uint cbInput, // DWORD
IntPtr pPaddingInfo, // void* optional
IntPtr pbOutput, // BYTE* optional, out
uint cbOutput, // DWORD
out uint pcbResult, // DWORD* out
uint dwFlags // NCRYPT_FLAGS
);<DllImport("ncrypt.dll", ExactSpelling:=True)>
Public Shared Function NCryptDecrypt(
hKey As UIntPtr, ' NCRYPT_KEY_HANDLE
pbInput As IntPtr, ' BYTE* optional
cbInput As UInteger, ' DWORD
pPaddingInfo As IntPtr, ' void* optional
pbOutput As IntPtr, ' BYTE* optional, out
cbOutput As UInteger, ' DWORD
<Out> ByRef pcbResult As UInteger, ' DWORD* out
dwFlags As UInteger ' NCRYPT_FLAGS
) As Integer
End Function' hKey : NCRYPT_KEY_HANDLE
' pbInput : BYTE* optional
' cbInput : DWORD
' pPaddingInfo : void* optional
' pbOutput : BYTE* optional, out
' cbOutput : DWORD
' pcbResult : DWORD* out
' dwFlags : NCRYPT_FLAGS
Declare PtrSafe Function NCryptDecrypt Lib "ncrypt" ( _
ByVal hKey As LongPtr, _
ByVal pbInput As LongPtr, _
ByVal cbInput As Long, _
ByVal pPaddingInfo As LongPtr, _
ByVal pbOutput As LongPtr, _
ByVal cbOutput As Long, _
ByRef pcbResult 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
NCryptDecrypt = ctypes.windll.ncrypt.NCryptDecrypt
NCryptDecrypt.restype = ctypes.c_int
NCryptDecrypt.argtypes = [
ctypes.c_size_t, # hKey : NCRYPT_KEY_HANDLE
ctypes.POINTER(ctypes.c_ubyte), # pbInput : BYTE* optional
wintypes.DWORD, # cbInput : DWORD
ctypes.POINTER(None), # pPaddingInfo : void* optional
ctypes.POINTER(ctypes.c_ubyte), # pbOutput : BYTE* optional, out
wintypes.DWORD, # cbOutput : DWORD
ctypes.POINTER(wintypes.DWORD), # pcbResult : DWORD* out
wintypes.DWORD, # dwFlags : NCRYPT_FLAGS
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ncrypt.dll')
NCryptDecrypt = Fiddle::Function.new(
lib['NCryptDecrypt'],
[
Fiddle::TYPE_UINTPTR_T, # hKey : NCRYPT_KEY_HANDLE
Fiddle::TYPE_VOIDP, # pbInput : BYTE* optional
-Fiddle::TYPE_INT, # cbInput : DWORD
Fiddle::TYPE_VOIDP, # pPaddingInfo : void* optional
Fiddle::TYPE_VOIDP, # pbOutput : BYTE* optional, out
-Fiddle::TYPE_INT, # cbOutput : DWORD
Fiddle::TYPE_VOIDP, # pcbResult : DWORD* out
-Fiddle::TYPE_INT, # dwFlags : NCRYPT_FLAGS
],
Fiddle::TYPE_INT)#[link(name = "ncrypt")]
extern "system" {
fn NCryptDecrypt(
hKey: usize, // NCRYPT_KEY_HANDLE
pbInput: *mut u8, // BYTE* optional
cbInput: u32, // DWORD
pPaddingInfo: *mut (), // void* optional
pbOutput: *mut u8, // BYTE* optional, out
cbOutput: u32, // DWORD
pcbResult: *mut u32, // DWORD* out
dwFlags: u32 // NCRYPT_FLAGS
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ncrypt.dll")]
public static extern int NCryptDecrypt(UIntPtr hKey, IntPtr pbInput, uint cbInput, IntPtr pPaddingInfo, IntPtr pbOutput, uint cbOutput, out uint pcbResult, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ncrypt_NCryptDecrypt' -Namespace Win32 -PassThru
# $api::NCryptDecrypt(hKey, pbInput, cbInput, pPaddingInfo, pbOutput, cbOutput, pcbResult, dwFlags)#uselib "ncrypt.dll"
#func global NCryptDecrypt "NCryptDecrypt" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; NCryptDecrypt hKey, varptr(pbInput), cbInput, pPaddingInfo, varptr(pbOutput), cbOutput, varptr(pcbResult), dwFlags ; 戻り値は stat
; hKey : NCRYPT_KEY_HANDLE -> "sptr"
; pbInput : BYTE* optional -> "sptr"
; cbInput : DWORD -> "sptr"
; pPaddingInfo : void* optional -> "sptr"
; pbOutput : BYTE* optional, out -> "sptr"
; cbOutput : DWORD -> "sptr"
; pcbResult : DWORD* out -> "sptr"
; dwFlags : NCRYPT_FLAGS -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ncrypt.dll" #cfunc global NCryptDecrypt "NCryptDecrypt" sptr, var, int, sptr, var, int, var, int ; res = NCryptDecrypt(hKey, pbInput, cbInput, pPaddingInfo, pbOutput, cbOutput, pcbResult, dwFlags) ; hKey : NCRYPT_KEY_HANDLE -> "sptr" ; pbInput : BYTE* optional -> "var" ; cbInput : DWORD -> "int" ; pPaddingInfo : void* optional -> "sptr" ; pbOutput : BYTE* optional, out -> "var" ; cbOutput : DWORD -> "int" ; pcbResult : DWORD* out -> "var" ; dwFlags : NCRYPT_FLAGS -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ncrypt.dll" #cfunc global NCryptDecrypt "NCryptDecrypt" sptr, sptr, int, sptr, sptr, int, sptr, int ; res = NCryptDecrypt(hKey, varptr(pbInput), cbInput, pPaddingInfo, varptr(pbOutput), cbOutput, varptr(pcbResult), dwFlags) ; hKey : NCRYPT_KEY_HANDLE -> "sptr" ; pbInput : BYTE* optional -> "sptr" ; cbInput : DWORD -> "int" ; pPaddingInfo : void* optional -> "sptr" ; pbOutput : BYTE* optional, out -> "sptr" ; cbOutput : DWORD -> "int" ; pcbResult : DWORD* out -> "sptr" ; dwFlags : NCRYPT_FLAGS -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT NCryptDecrypt(NCRYPT_KEY_HANDLE hKey, BYTE* pbInput, DWORD cbInput, void* pPaddingInfo, BYTE* pbOutput, DWORD cbOutput, DWORD* pcbResult, NCRYPT_FLAGS dwFlags) #uselib "ncrypt.dll" #cfunc global NCryptDecrypt "NCryptDecrypt" intptr, var, int, intptr, var, int, var, int ; res = NCryptDecrypt(hKey, pbInput, cbInput, pPaddingInfo, pbOutput, cbOutput, pcbResult, dwFlags) ; hKey : NCRYPT_KEY_HANDLE -> "intptr" ; pbInput : BYTE* optional -> "var" ; cbInput : DWORD -> "int" ; pPaddingInfo : void* optional -> "intptr" ; pbOutput : BYTE* optional, out -> "var" ; cbOutput : DWORD -> "int" ; pcbResult : DWORD* out -> "var" ; dwFlags : NCRYPT_FLAGS -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT NCryptDecrypt(NCRYPT_KEY_HANDLE hKey, BYTE* pbInput, DWORD cbInput, void* pPaddingInfo, BYTE* pbOutput, DWORD cbOutput, DWORD* pcbResult, NCRYPT_FLAGS dwFlags) #uselib "ncrypt.dll" #cfunc global NCryptDecrypt "NCryptDecrypt" intptr, intptr, int, intptr, intptr, int, intptr, int ; res = NCryptDecrypt(hKey, varptr(pbInput), cbInput, pPaddingInfo, varptr(pbOutput), cbOutput, varptr(pcbResult), dwFlags) ; hKey : NCRYPT_KEY_HANDLE -> "intptr" ; pbInput : BYTE* optional -> "intptr" ; cbInput : DWORD -> "int" ; pPaddingInfo : void* optional -> "intptr" ; pbOutput : BYTE* optional, out -> "intptr" ; cbOutput : DWORD -> "int" ; pcbResult : DWORD* out -> "intptr" ; dwFlags : NCRYPT_FLAGS -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ncrypt = windows.NewLazySystemDLL("ncrypt.dll")
procNCryptDecrypt = ncrypt.NewProc("NCryptDecrypt")
)
// hKey (NCRYPT_KEY_HANDLE), pbInput (BYTE* optional), cbInput (DWORD), pPaddingInfo (void* optional), pbOutput (BYTE* optional, out), cbOutput (DWORD), pcbResult (DWORD* out), dwFlags (NCRYPT_FLAGS)
r1, _, err := procNCryptDecrypt.Call(
uintptr(hKey),
uintptr(pbInput),
uintptr(cbInput),
uintptr(pPaddingInfo),
uintptr(pbOutput),
uintptr(cbOutput),
uintptr(pcbResult),
uintptr(dwFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction NCryptDecrypt(
hKey: NativeUInt; // NCRYPT_KEY_HANDLE
pbInput: Pointer; // BYTE* optional
cbInput: DWORD; // DWORD
pPaddingInfo: Pointer; // void* optional
pbOutput: Pointer; // BYTE* optional, out
cbOutput: DWORD; // DWORD
pcbResult: Pointer; // DWORD* out
dwFlags: DWORD // NCRYPT_FLAGS
): Integer; stdcall;
external 'ncrypt.dll' name 'NCryptDecrypt';result := DllCall("ncrypt\NCryptDecrypt"
, "UPtr", hKey ; NCRYPT_KEY_HANDLE
, "Ptr", pbInput ; BYTE* optional
, "UInt", cbInput ; DWORD
, "Ptr", pPaddingInfo ; void* optional
, "Ptr", pbOutput ; BYTE* optional, out
, "UInt", cbOutput ; DWORD
, "Ptr", pcbResult ; DWORD* out
, "UInt", dwFlags ; NCRYPT_FLAGS
, "Int") ; return: HRESULT●NCryptDecrypt(hKey, pbInput, cbInput, pPaddingInfo, pbOutput, cbOutput, pcbResult, dwFlags) = DLL("ncrypt.dll", "int NCryptDecrypt(int, void*, dword, void*, void*, dword, void*, dword)")
# 呼び出し: NCryptDecrypt(hKey, pbInput, cbInput, pPaddingInfo, pbOutput, cbOutput, pcbResult, dwFlags)
# hKey : NCRYPT_KEY_HANDLE -> "int"
# pbInput : BYTE* optional -> "void*"
# cbInput : DWORD -> "dword"
# pPaddingInfo : void* optional -> "void*"
# pbOutput : BYTE* optional, out -> "void*"
# cbOutput : DWORD -> "dword"
# pcbResult : DWORD* out -> "void*"
# dwFlags : NCRYPT_FLAGS -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。