Win32 API 日本語リファレンス
ホームSecurity.Cryptography › SslGetKeyProperty

SslGetKeyProperty

関数
SSL鍵の指定プロパティを取得する。
DLLncrypt.dll呼出規約winapi

シグネチャ

// ncrypt.dll
#include <windows.h>

HRESULT SslGetKeyProperty(
    NCRYPT_KEY_HANDLE hKey,
    LPCWSTR pszProperty,
    BYTE** ppbOutput,
    DWORD* pcbOutput,
    DWORD dwFlags
);

パラメーター

名前方向
hKeyNCRYPT_KEY_HANDLEin
pszPropertyLPCWSTRin
ppbOutputBYTE**out
pcbOutputDWORD*out
dwFlagsDWORDin

戻り値の型: HRESULT

各言語での呼び出し定義

// ncrypt.dll
#include <windows.h>

HRESULT SslGetKeyProperty(
    NCRYPT_KEY_HANDLE hKey,
    LPCWSTR pszProperty,
    BYTE** ppbOutput,
    DWORD* pcbOutput,
    DWORD dwFlags
);
[DllImport("ncrypt.dll", ExactSpelling = true)]
static extern int SslGetKeyProperty(
    UIntPtr hKey,   // NCRYPT_KEY_HANDLE
    [MarshalAs(UnmanagedType.LPWStr)] string pszProperty,   // LPCWSTR
    IntPtr ppbOutput,   // BYTE** out
    out uint pcbOutput,   // DWORD* out
    uint dwFlags   // DWORD
);
<DllImport("ncrypt.dll", ExactSpelling:=True)>
Public Shared Function SslGetKeyProperty(
    hKey As UIntPtr,   ' NCRYPT_KEY_HANDLE
    <MarshalAs(UnmanagedType.LPWStr)> pszProperty As String,   ' LPCWSTR
    ppbOutput As IntPtr,   ' BYTE** out
    <Out> ByRef pcbOutput As UInteger,   ' DWORD* out
    dwFlags As UInteger   ' DWORD
) As Integer
End Function
' hKey : NCRYPT_KEY_HANDLE
' pszProperty : LPCWSTR
' ppbOutput : BYTE** out
' pcbOutput : DWORD* out
' dwFlags : DWORD
Declare PtrSafe Function SslGetKeyProperty Lib "ncrypt" ( _
    ByVal hKey As LongPtr, _
    ByVal pszProperty As LongPtr, _
    ByVal ppbOutput As LongPtr, _
    ByRef pcbOutput 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

SslGetKeyProperty = ctypes.windll.ncrypt.SslGetKeyProperty
SslGetKeyProperty.restype = ctypes.c_int
SslGetKeyProperty.argtypes = [
    ctypes.c_size_t,  # hKey : NCRYPT_KEY_HANDLE
    wintypes.LPCWSTR,  # pszProperty : LPCWSTR
    ctypes.c_void_p,  # ppbOutput : BYTE** out
    ctypes.POINTER(wintypes.DWORD),  # pcbOutput : DWORD* out
    wintypes.DWORD,  # dwFlags : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ncrypt.dll')
SslGetKeyProperty = Fiddle::Function.new(
  lib['SslGetKeyProperty'],
  [
    Fiddle::TYPE_UINTPTR_T,  # hKey : NCRYPT_KEY_HANDLE
    Fiddle::TYPE_VOIDP,  # pszProperty : LPCWSTR
    Fiddle::TYPE_VOIDP,  # ppbOutput : BYTE** out
    Fiddle::TYPE_VOIDP,  # pcbOutput : DWORD* out
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "ncrypt")]
extern "system" {
    fn SslGetKeyProperty(
        hKey: usize,  // NCRYPT_KEY_HANDLE
        pszProperty: *const u16,  // LPCWSTR
        ppbOutput: *mut *mut u8,  // BYTE** out
        pcbOutput: *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 SslGetKeyProperty(UIntPtr hKey, [MarshalAs(UnmanagedType.LPWStr)] string pszProperty, IntPtr ppbOutput, out uint pcbOutput, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ncrypt_SslGetKeyProperty' -Namespace Win32 -PassThru
# $api::SslGetKeyProperty(hKey, pszProperty, ppbOutput, pcbOutput, dwFlags)
#uselib "ncrypt.dll"
#func global SslGetKeyProperty "SslGetKeyProperty" sptr, sptr, sptr, sptr, sptr
; SslGetKeyProperty hKey, pszProperty, varptr(ppbOutput), varptr(pcbOutput), dwFlags   ; 戻り値は stat
; hKey : NCRYPT_KEY_HANDLE -> "sptr"
; pszProperty : LPCWSTR -> "sptr"
; ppbOutput : BYTE** out -> "sptr"
; pcbOutput : DWORD* out -> "sptr"
; dwFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ncrypt.dll"
#cfunc global SslGetKeyProperty "SslGetKeyProperty" sptr, wstr, var, var, int
; res = SslGetKeyProperty(hKey, pszProperty, ppbOutput, pcbOutput, dwFlags)
; hKey : NCRYPT_KEY_HANDLE -> "sptr"
; pszProperty : LPCWSTR -> "wstr"
; ppbOutput : BYTE** out -> "var"
; pcbOutput : DWORD* out -> "var"
; dwFlags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT SslGetKeyProperty(NCRYPT_KEY_HANDLE hKey, LPCWSTR pszProperty, BYTE** ppbOutput, DWORD* pcbOutput, DWORD dwFlags)
#uselib "ncrypt.dll"
#cfunc global SslGetKeyProperty "SslGetKeyProperty" intptr, wstr, var, var, int
; res = SslGetKeyProperty(hKey, pszProperty, ppbOutput, pcbOutput, dwFlags)
; hKey : NCRYPT_KEY_HANDLE -> "intptr"
; pszProperty : LPCWSTR -> "wstr"
; ppbOutput : BYTE** out -> "var"
; pcbOutput : DWORD* out -> "var"
; dwFlags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ncrypt = windows.NewLazySystemDLL("ncrypt.dll")
	procSslGetKeyProperty = ncrypt.NewProc("SslGetKeyProperty")
)

// hKey (NCRYPT_KEY_HANDLE), pszProperty (LPCWSTR), ppbOutput (BYTE** out), pcbOutput (DWORD* out), dwFlags (DWORD)
r1, _, err := procSslGetKeyProperty.Call(
	uintptr(hKey),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszProperty))),
	uintptr(ppbOutput),
	uintptr(pcbOutput),
	uintptr(dwFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function SslGetKeyProperty(
  hKey: NativeUInt;   // NCRYPT_KEY_HANDLE
  pszProperty: PWideChar;   // LPCWSTR
  ppbOutput: Pointer;   // BYTE** out
  pcbOutput: Pointer;   // DWORD* out
  dwFlags: DWORD   // DWORD
): Integer; stdcall;
  external 'ncrypt.dll' name 'SslGetKeyProperty';
result := DllCall("ncrypt\SslGetKeyProperty"
    , "UPtr", hKey   ; NCRYPT_KEY_HANDLE
    , "WStr", pszProperty   ; LPCWSTR
    , "Ptr", ppbOutput   ; BYTE** out
    , "Ptr", pcbOutput   ; DWORD* out
    , "UInt", dwFlags   ; DWORD
    , "Int")   ; return: HRESULT
●SslGetKeyProperty(hKey, pszProperty, ppbOutput, pcbOutput, dwFlags) = DLL("ncrypt.dll", "int SslGetKeyProperty(int, char*, void*, void*, dword)")
# 呼び出し: SslGetKeyProperty(hKey, pszProperty, ppbOutput, pcbOutput, dwFlags)
# hKey : NCRYPT_KEY_HANDLE -> "int"
# pszProperty : LPCWSTR -> "char*"
# ppbOutput : BYTE** out -> "void*"
# pcbOutput : DWORD* out -> "void*"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。