ホーム › Security.Cryptography › NCryptTranslateHandle
NCryptTranslateHandle
関数レガシーCryptoAPIハンドルをCNGハンドルに変換する。
シグネチャ
// ncrypt.dll
#include <windows.h>
HRESULT NCryptTranslateHandle(
NCRYPT_PROV_HANDLE* phProvider, // optional
NCRYPT_KEY_HANDLE* phKey,
UINT_PTR hLegacyProv,
UINT_PTR hLegacyKey, // optional
CERT_KEY_SPEC dwLegacyKeySpec, // optional
DWORD dwFlags
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| phProvider | NCRYPT_PROV_HANDLE* | outoptional |
| phKey | NCRYPT_KEY_HANDLE* | out |
| hLegacyProv | UINT_PTR | in |
| hLegacyKey | UINT_PTR | inoptional |
| dwLegacyKeySpec | CERT_KEY_SPEC | inoptional |
| dwFlags | DWORD | in |
戻り値の型: HRESULT
各言語での呼び出し定義
// ncrypt.dll
#include <windows.h>
HRESULT NCryptTranslateHandle(
NCRYPT_PROV_HANDLE* phProvider, // optional
NCRYPT_KEY_HANDLE* phKey,
UINT_PTR hLegacyProv,
UINT_PTR hLegacyKey, // optional
CERT_KEY_SPEC dwLegacyKeySpec, // optional
DWORD dwFlags
);[DllImport("ncrypt.dll", ExactSpelling = true)]
static extern int NCryptTranslateHandle(
IntPtr phProvider, // NCRYPT_PROV_HANDLE* optional, out
out UIntPtr phKey, // NCRYPT_KEY_HANDLE* out
UIntPtr hLegacyProv, // UINT_PTR
UIntPtr hLegacyKey, // UINT_PTR optional
uint dwLegacyKeySpec, // CERT_KEY_SPEC optional
uint dwFlags // DWORD
);<DllImport("ncrypt.dll", ExactSpelling:=True)>
Public Shared Function NCryptTranslateHandle(
phProvider As IntPtr, ' NCRYPT_PROV_HANDLE* optional, out
<Out> ByRef phKey As UIntPtr, ' NCRYPT_KEY_HANDLE* out
hLegacyProv As UIntPtr, ' UINT_PTR
hLegacyKey As UIntPtr, ' UINT_PTR optional
dwLegacyKeySpec As UInteger, ' CERT_KEY_SPEC optional
dwFlags As UInteger ' DWORD
) As Integer
End Function' phProvider : NCRYPT_PROV_HANDLE* optional, out
' phKey : NCRYPT_KEY_HANDLE* out
' hLegacyProv : UINT_PTR
' hLegacyKey : UINT_PTR optional
' dwLegacyKeySpec : CERT_KEY_SPEC optional
' dwFlags : DWORD
Declare PtrSafe Function NCryptTranslateHandle Lib "ncrypt" ( _
ByVal phProvider As LongPtr, _
ByRef phKey As LongPtr, _
ByVal hLegacyProv As LongPtr, _
ByVal hLegacyKey As LongPtr, _
ByVal dwLegacyKeySpec 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
NCryptTranslateHandle = ctypes.windll.ncrypt.NCryptTranslateHandle
NCryptTranslateHandle.restype = ctypes.c_int
NCryptTranslateHandle.argtypes = [
ctypes.c_void_p, # phProvider : NCRYPT_PROV_HANDLE* optional, out
ctypes.c_void_p, # phKey : NCRYPT_KEY_HANDLE* out
ctypes.c_size_t, # hLegacyProv : UINT_PTR
ctypes.c_size_t, # hLegacyKey : UINT_PTR optional
wintypes.DWORD, # dwLegacyKeySpec : CERT_KEY_SPEC optional
wintypes.DWORD, # dwFlags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ncrypt.dll')
NCryptTranslateHandle = Fiddle::Function.new(
lib['NCryptTranslateHandle'],
[
Fiddle::TYPE_VOIDP, # phProvider : NCRYPT_PROV_HANDLE* optional, out
Fiddle::TYPE_VOIDP, # phKey : NCRYPT_KEY_HANDLE* out
Fiddle::TYPE_UINTPTR_T, # hLegacyProv : UINT_PTR
Fiddle::TYPE_UINTPTR_T, # hLegacyKey : UINT_PTR optional
-Fiddle::TYPE_INT, # dwLegacyKeySpec : CERT_KEY_SPEC optional
-Fiddle::TYPE_INT, # dwFlags : DWORD
],
Fiddle::TYPE_INT)#[link(name = "ncrypt")]
extern "system" {
fn NCryptTranslateHandle(
phProvider: *mut usize, // NCRYPT_PROV_HANDLE* optional, out
phKey: *mut usize, // NCRYPT_KEY_HANDLE* out
hLegacyProv: usize, // UINT_PTR
hLegacyKey: usize, // UINT_PTR optional
dwLegacyKeySpec: u32, // CERT_KEY_SPEC optional
dwFlags: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ncrypt.dll")]
public static extern int NCryptTranslateHandle(IntPtr phProvider, out UIntPtr phKey, UIntPtr hLegacyProv, UIntPtr hLegacyKey, uint dwLegacyKeySpec, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ncrypt_NCryptTranslateHandle' -Namespace Win32 -PassThru
# $api::NCryptTranslateHandle(phProvider, phKey, hLegacyProv, hLegacyKey, dwLegacyKeySpec, dwFlags)#uselib "ncrypt.dll"
#func global NCryptTranslateHandle "NCryptTranslateHandle" sptr, sptr, sptr, sptr, sptr, sptr
; NCryptTranslateHandle phProvider, phKey, hLegacyProv, hLegacyKey, dwLegacyKeySpec, dwFlags ; 戻り値は stat
; phProvider : NCRYPT_PROV_HANDLE* optional, out -> "sptr"
; phKey : NCRYPT_KEY_HANDLE* out -> "sptr"
; hLegacyProv : UINT_PTR -> "sptr"
; hLegacyKey : UINT_PTR optional -> "sptr"
; dwLegacyKeySpec : CERT_KEY_SPEC optional -> "sptr"
; dwFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ncrypt.dll"
#cfunc global NCryptTranslateHandle "NCryptTranslateHandle" int, int, sptr, sptr, int, int
; res = NCryptTranslateHandle(phProvider, phKey, hLegacyProv, hLegacyKey, dwLegacyKeySpec, dwFlags)
; phProvider : NCRYPT_PROV_HANDLE* optional, out -> "int"
; phKey : NCRYPT_KEY_HANDLE* out -> "int"
; hLegacyProv : UINT_PTR -> "sptr"
; hLegacyKey : UINT_PTR optional -> "sptr"
; dwLegacyKeySpec : CERT_KEY_SPEC optional -> "int"
; dwFlags : DWORD -> "int"; HRESULT NCryptTranslateHandle(NCRYPT_PROV_HANDLE* phProvider, NCRYPT_KEY_HANDLE* phKey, UINT_PTR hLegacyProv, UINT_PTR hLegacyKey, CERT_KEY_SPEC dwLegacyKeySpec, DWORD dwFlags)
#uselib "ncrypt.dll"
#cfunc global NCryptTranslateHandle "NCryptTranslateHandle" int, int, intptr, intptr, int, int
; res = NCryptTranslateHandle(phProvider, phKey, hLegacyProv, hLegacyKey, dwLegacyKeySpec, dwFlags)
; phProvider : NCRYPT_PROV_HANDLE* optional, out -> "int"
; phKey : NCRYPT_KEY_HANDLE* out -> "int"
; hLegacyProv : UINT_PTR -> "intptr"
; hLegacyKey : UINT_PTR optional -> "intptr"
; dwLegacyKeySpec : CERT_KEY_SPEC optional -> "int"
; dwFlags : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ncrypt = windows.NewLazySystemDLL("ncrypt.dll")
procNCryptTranslateHandle = ncrypt.NewProc("NCryptTranslateHandle")
)
// phProvider (NCRYPT_PROV_HANDLE* optional, out), phKey (NCRYPT_KEY_HANDLE* out), hLegacyProv (UINT_PTR), hLegacyKey (UINT_PTR optional), dwLegacyKeySpec (CERT_KEY_SPEC optional), dwFlags (DWORD)
r1, _, err := procNCryptTranslateHandle.Call(
uintptr(phProvider),
uintptr(phKey),
uintptr(hLegacyProv),
uintptr(hLegacyKey),
uintptr(dwLegacyKeySpec),
uintptr(dwFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction NCryptTranslateHandle(
phProvider: Pointer; // NCRYPT_PROV_HANDLE* optional, out
phKey: Pointer; // NCRYPT_KEY_HANDLE* out
hLegacyProv: NativeUInt; // UINT_PTR
hLegacyKey: NativeUInt; // UINT_PTR optional
dwLegacyKeySpec: DWORD; // CERT_KEY_SPEC optional
dwFlags: DWORD // DWORD
): Integer; stdcall;
external 'ncrypt.dll' name 'NCryptTranslateHandle';result := DllCall("ncrypt\NCryptTranslateHandle"
, "Ptr", phProvider ; NCRYPT_PROV_HANDLE* optional, out
, "Ptr", phKey ; NCRYPT_KEY_HANDLE* out
, "UPtr", hLegacyProv ; UINT_PTR
, "UPtr", hLegacyKey ; UINT_PTR optional
, "UInt", dwLegacyKeySpec ; CERT_KEY_SPEC optional
, "UInt", dwFlags ; DWORD
, "Int") ; return: HRESULT●NCryptTranslateHandle(phProvider, phKey, hLegacyProv, hLegacyKey, dwLegacyKeySpec, dwFlags) = DLL("ncrypt.dll", "int NCryptTranslateHandle(void*, void*, int, int, dword, dword)")
# 呼び出し: NCryptTranslateHandle(phProvider, phKey, hLegacyProv, hLegacyKey, dwLegacyKeySpec, dwFlags)
# phProvider : NCRYPT_PROV_HANDLE* optional, out -> "void*"
# phKey : NCRYPT_KEY_HANDLE* out -> "void*"
# hLegacyProv : UINT_PTR -> "int"
# hLegacyKey : UINT_PTR optional -> "int"
# dwLegacyKeySpec : CERT_KEY_SPEC optional -> "dword"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。