ホーム › Security.Cryptography › CryptGetUserKey
CryptGetUserKey
関数プロバイダーの永続的なユーザー鍵ペアのハンドルを取得する。
シグネチャ
// ADVAPI32.dll
#include <windows.h>
BOOL CryptGetUserKey(
UINT_PTR hProv,
DWORD dwKeySpec,
UINT_PTR* phUserKey
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hProv | UINT_PTR | in |
| dwKeySpec | DWORD | in |
| phUserKey | UINT_PTR* | out |
戻り値の型: BOOL
各言語での呼び出し定義
// ADVAPI32.dll
#include <windows.h>
BOOL CryptGetUserKey(
UINT_PTR hProv,
DWORD dwKeySpec,
UINT_PTR* phUserKey
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CryptGetUserKey(
UIntPtr hProv, // UINT_PTR
uint dwKeySpec, // DWORD
out UIntPtr phUserKey // UINT_PTR* out
);<DllImport("ADVAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CryptGetUserKey(
hProv As UIntPtr, ' UINT_PTR
dwKeySpec As UInteger, ' DWORD
<Out> ByRef phUserKey As UIntPtr ' UINT_PTR* out
) As Boolean
End Function' hProv : UINT_PTR
' dwKeySpec : DWORD
' phUserKey : UINT_PTR* out
Declare PtrSafe Function CryptGetUserKey Lib "advapi32" ( _
ByVal hProv As LongPtr, _
ByVal dwKeySpec As Long, _
ByRef phUserKey As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CryptGetUserKey = ctypes.windll.advapi32.CryptGetUserKey
CryptGetUserKey.restype = wintypes.BOOL
CryptGetUserKey.argtypes = [
ctypes.c_size_t, # hProv : UINT_PTR
wintypes.DWORD, # dwKeySpec : DWORD
ctypes.POINTER(ctypes.c_size_t), # phUserKey : UINT_PTR* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
CryptGetUserKey = Fiddle::Function.new(
lib['CryptGetUserKey'],
[
Fiddle::TYPE_UINTPTR_T, # hProv : UINT_PTR
-Fiddle::TYPE_INT, # dwKeySpec : DWORD
Fiddle::TYPE_VOIDP, # phUserKey : UINT_PTR* out
],
Fiddle::TYPE_INT)#[link(name = "advapi32")]
extern "system" {
fn CryptGetUserKey(
hProv: usize, // UINT_PTR
dwKeySpec: u32, // DWORD
phUserKey: *mut usize // UINT_PTR* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true)]
public static extern bool CryptGetUserKey(UIntPtr hProv, uint dwKeySpec, out UIntPtr phUserKey);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_CryptGetUserKey' -Namespace Win32 -PassThru
# $api::CryptGetUserKey(hProv, dwKeySpec, phUserKey)#uselib "ADVAPI32.dll"
#func global CryptGetUserKey "CryptGetUserKey" sptr, sptr, sptr
; CryptGetUserKey hProv, dwKeySpec, varptr(phUserKey) ; 戻り値は stat
; hProv : UINT_PTR -> "sptr"
; dwKeySpec : DWORD -> "sptr"
; phUserKey : UINT_PTR* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ADVAPI32.dll" #cfunc global CryptGetUserKey "CryptGetUserKey" sptr, int, var ; res = CryptGetUserKey(hProv, dwKeySpec, phUserKey) ; hProv : UINT_PTR -> "sptr" ; dwKeySpec : DWORD -> "int" ; phUserKey : UINT_PTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ADVAPI32.dll" #cfunc global CryptGetUserKey "CryptGetUserKey" sptr, int, sptr ; res = CryptGetUserKey(hProv, dwKeySpec, varptr(phUserKey)) ; hProv : UINT_PTR -> "sptr" ; dwKeySpec : DWORD -> "int" ; phUserKey : UINT_PTR* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL CryptGetUserKey(UINT_PTR hProv, DWORD dwKeySpec, UINT_PTR* phUserKey) #uselib "ADVAPI32.dll" #cfunc global CryptGetUserKey "CryptGetUserKey" intptr, int, var ; res = CryptGetUserKey(hProv, dwKeySpec, phUserKey) ; hProv : UINT_PTR -> "intptr" ; dwKeySpec : DWORD -> "int" ; phUserKey : UINT_PTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL CryptGetUserKey(UINT_PTR hProv, DWORD dwKeySpec, UINT_PTR* phUserKey) #uselib "ADVAPI32.dll" #cfunc global CryptGetUserKey "CryptGetUserKey" intptr, int, intptr ; res = CryptGetUserKey(hProv, dwKeySpec, varptr(phUserKey)) ; hProv : UINT_PTR -> "intptr" ; dwKeySpec : DWORD -> "int" ; phUserKey : UINT_PTR* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procCryptGetUserKey = advapi32.NewProc("CryptGetUserKey")
)
// hProv (UINT_PTR), dwKeySpec (DWORD), phUserKey (UINT_PTR* out)
r1, _, err := procCryptGetUserKey.Call(
uintptr(hProv),
uintptr(dwKeySpec),
uintptr(phUserKey),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CryptGetUserKey(
hProv: NativeUInt; // UINT_PTR
dwKeySpec: DWORD; // DWORD
phUserKey: Pointer // UINT_PTR* out
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'CryptGetUserKey';result := DllCall("ADVAPI32\CryptGetUserKey"
, "UPtr", hProv ; UINT_PTR
, "UInt", dwKeySpec ; DWORD
, "Ptr", phUserKey ; UINT_PTR* out
, "Int") ; return: BOOL●CryptGetUserKey(hProv, dwKeySpec, phUserKey) = DLL("ADVAPI32.dll", "bool CryptGetUserKey(int, dword, void*)")
# 呼び出し: CryptGetUserKey(hProv, dwKeySpec, phUserKey)
# hProv : UINT_PTR -> "int"
# dwKeySpec : DWORD -> "dword"
# phUserKey : UINT_PTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。