ホーム › Security.Cryptography › GetAsymmetricEncryptionInterface
GetAsymmetricEncryptionInterface
関数プロバイダーの非対称暗号化関数テーブルを取得する。
シグネチャ
// bcryptprimitives.dll
#include <windows.h>
NTSTATUS GetAsymmetricEncryptionInterface(
LPCWSTR pszProviderName,
LPCWSTR pszAlgId,
BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** ppFunctionTable,
DWORD dwFlags
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pszProviderName | LPCWSTR | in | 対象の暗号化プロバイダ名。NULLで既定プロバイダ。 |
| pszAlgId | LPCWSTR | in | 対象の非対称暗号アルゴリズム識別子文字列。 |
| ppFunctionTable | BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** | out | 非対称暗号の関数テーブルBCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLEへのポインタを受け取る出力先。 |
| dwFlags | DWORD | in | 動作を制御するフラグ。 |
戻り値の型: NTSTATUS
各言語での呼び出し定義
// bcryptprimitives.dll
#include <windows.h>
NTSTATUS GetAsymmetricEncryptionInterface(
LPCWSTR pszProviderName,
LPCWSTR pszAlgId,
BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** ppFunctionTable,
DWORD dwFlags
);[DllImport("bcryptprimitives.dll", ExactSpelling = true)]
static extern int GetAsymmetricEncryptionInterface(
[MarshalAs(UnmanagedType.LPWStr)] string pszProviderName, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string pszAlgId, // LPCWSTR
IntPtr ppFunctionTable, // BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out
uint dwFlags // DWORD
);<DllImport("bcryptprimitives.dll", ExactSpelling:=True)>
Public Shared Function GetAsymmetricEncryptionInterface(
<MarshalAs(UnmanagedType.LPWStr)> pszProviderName As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> pszAlgId As String, ' LPCWSTR
ppFunctionTable As IntPtr, ' BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out
dwFlags As UInteger ' DWORD
) As Integer
End Function' pszProviderName : LPCWSTR
' pszAlgId : LPCWSTR
' ppFunctionTable : BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out
' dwFlags : DWORD
Declare PtrSafe Function GetAsymmetricEncryptionInterface Lib "bcryptprimitives" ( _
ByVal pszProviderName As LongPtr, _
ByVal pszAlgId As LongPtr, _
ByVal ppFunctionTable As LongPtr, _
ByVal dwFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetAsymmetricEncryptionInterface = ctypes.windll.bcryptprimitives.GetAsymmetricEncryptionInterface
GetAsymmetricEncryptionInterface.restype = ctypes.c_int
GetAsymmetricEncryptionInterface.argtypes = [
wintypes.LPCWSTR, # pszProviderName : LPCWSTR
wintypes.LPCWSTR, # pszAlgId : LPCWSTR
ctypes.c_void_p, # ppFunctionTable : BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out
wintypes.DWORD, # dwFlags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('bcryptprimitives.dll')
GetAsymmetricEncryptionInterface = Fiddle::Function.new(
lib['GetAsymmetricEncryptionInterface'],
[
Fiddle::TYPE_VOIDP, # pszProviderName : LPCWSTR
Fiddle::TYPE_VOIDP, # pszAlgId : LPCWSTR
Fiddle::TYPE_VOIDP, # ppFunctionTable : BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out
-Fiddle::TYPE_INT, # dwFlags : DWORD
],
Fiddle::TYPE_INT)#[link(name = "bcryptprimitives")]
extern "system" {
fn GetAsymmetricEncryptionInterface(
pszProviderName: *const u16, // LPCWSTR
pszAlgId: *const u16, // LPCWSTR
ppFunctionTable: *mut *mut BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE, // BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out
dwFlags: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("bcryptprimitives.dll")]
public static extern int GetAsymmetricEncryptionInterface([MarshalAs(UnmanagedType.LPWStr)] string pszProviderName, [MarshalAs(UnmanagedType.LPWStr)] string pszAlgId, IntPtr ppFunctionTable, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'bcryptprimitives_GetAsymmetricEncryptionInterface' -Namespace Win32 -PassThru
# $api::GetAsymmetricEncryptionInterface(pszProviderName, pszAlgId, ppFunctionTable, dwFlags)#uselib "bcryptprimitives.dll"
#func global GetAsymmetricEncryptionInterface "GetAsymmetricEncryptionInterface" sptr, sptr, sptr, sptr
; GetAsymmetricEncryptionInterface pszProviderName, pszAlgId, varptr(ppFunctionTable), dwFlags ; 戻り値は stat
; pszProviderName : LPCWSTR -> "sptr"
; pszAlgId : LPCWSTR -> "sptr"
; ppFunctionTable : BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out -> "sptr"
; dwFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "bcryptprimitives.dll" #cfunc global GetAsymmetricEncryptionInterface "GetAsymmetricEncryptionInterface" wstr, wstr, var, int ; res = GetAsymmetricEncryptionInterface(pszProviderName, pszAlgId, ppFunctionTable, dwFlags) ; pszProviderName : LPCWSTR -> "wstr" ; pszAlgId : LPCWSTR -> "wstr" ; ppFunctionTable : BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out -> "var" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "bcryptprimitives.dll" #cfunc global GetAsymmetricEncryptionInterface "GetAsymmetricEncryptionInterface" wstr, wstr, sptr, int ; res = GetAsymmetricEncryptionInterface(pszProviderName, pszAlgId, varptr(ppFunctionTable), dwFlags) ; pszProviderName : LPCWSTR -> "wstr" ; pszAlgId : LPCWSTR -> "wstr" ; ppFunctionTable : BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out -> "sptr" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; NTSTATUS GetAsymmetricEncryptionInterface(LPCWSTR pszProviderName, LPCWSTR pszAlgId, BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** ppFunctionTable, DWORD dwFlags) #uselib "bcryptprimitives.dll" #cfunc global GetAsymmetricEncryptionInterface "GetAsymmetricEncryptionInterface" wstr, wstr, var, int ; res = GetAsymmetricEncryptionInterface(pszProviderName, pszAlgId, ppFunctionTable, dwFlags) ; pszProviderName : LPCWSTR -> "wstr" ; pszAlgId : LPCWSTR -> "wstr" ; ppFunctionTable : BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out -> "var" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; NTSTATUS GetAsymmetricEncryptionInterface(LPCWSTR pszProviderName, LPCWSTR pszAlgId, BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** ppFunctionTable, DWORD dwFlags) #uselib "bcryptprimitives.dll" #cfunc global GetAsymmetricEncryptionInterface "GetAsymmetricEncryptionInterface" wstr, wstr, intptr, int ; res = GetAsymmetricEncryptionInterface(pszProviderName, pszAlgId, varptr(ppFunctionTable), dwFlags) ; pszProviderName : LPCWSTR -> "wstr" ; pszAlgId : LPCWSTR -> "wstr" ; ppFunctionTable : BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out -> "intptr" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
bcryptprimitives = windows.NewLazySystemDLL("bcryptprimitives.dll")
procGetAsymmetricEncryptionInterface = bcryptprimitives.NewProc("GetAsymmetricEncryptionInterface")
)
// pszProviderName (LPCWSTR), pszAlgId (LPCWSTR), ppFunctionTable (BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out), dwFlags (DWORD)
r1, _, err := procGetAsymmetricEncryptionInterface.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszProviderName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszAlgId))),
uintptr(ppFunctionTable),
uintptr(dwFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // NTSTATUSfunction GetAsymmetricEncryptionInterface(
pszProviderName: PWideChar; // LPCWSTR
pszAlgId: PWideChar; // LPCWSTR
ppFunctionTable: Pointer; // BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out
dwFlags: DWORD // DWORD
): Integer; stdcall;
external 'bcryptprimitives.dll' name 'GetAsymmetricEncryptionInterface';result := DllCall("bcryptprimitives\GetAsymmetricEncryptionInterface"
, "WStr", pszProviderName ; LPCWSTR
, "WStr", pszAlgId ; LPCWSTR
, "Ptr", ppFunctionTable ; BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out
, "UInt", dwFlags ; DWORD
, "Int") ; return: NTSTATUS●GetAsymmetricEncryptionInterface(pszProviderName, pszAlgId, ppFunctionTable, dwFlags) = DLL("bcryptprimitives.dll", "int GetAsymmetricEncryptionInterface(char*, char*, void*, dword)")
# 呼び出し: GetAsymmetricEncryptionInterface(pszProviderName, pszAlgId, ppFunctionTable, dwFlags)
# pszProviderName : LPCWSTR -> "char*"
# pszAlgId : LPCWSTR -> "char*"
# ppFunctionTable : BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out -> "void*"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "bcryptprimitives" fn GetAsymmetricEncryptionInterface(
pszProviderName: [*c]const u16, // LPCWSTR
pszAlgId: [*c]const u16, // LPCWSTR
ppFunctionTable: [*c][*c]BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE, // BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out
dwFlags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc GetAsymmetricEncryptionInterface(
pszProviderName: WideCString, # LPCWSTR
pszAlgId: WideCString, # LPCWSTR
ppFunctionTable: ptr BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE, # BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out
dwFlags: uint32 # DWORD
): int32 {.importc: "GetAsymmetricEncryptionInterface", stdcall, dynlib: "bcryptprimitives.dll".}pragma(lib, "bcryptprimitives");
extern(Windows)
int GetAsymmetricEncryptionInterface(
const(wchar)* pszProviderName, // LPCWSTR
const(wchar)* pszAlgId, // LPCWSTR
BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** ppFunctionTable, // BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out
uint dwFlags // DWORD
);ccall((:GetAsymmetricEncryptionInterface, "bcryptprimitives.dll"), stdcall, Int32,
(Cwstring, Cwstring, Ptr{BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE}, UInt32),
pszProviderName, pszAlgId, ppFunctionTable, dwFlags)
# pszProviderName : LPCWSTR -> Cwstring
# pszAlgId : LPCWSTR -> Cwstring
# ppFunctionTable : BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out -> Ptr{BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE}
# dwFlags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetAsymmetricEncryptionInterface(
const uint16_t* pszProviderName,
const uint16_t* pszAlgId,
void* ppFunctionTable,
uint32_t dwFlags);
]]
local bcryptprimitives = ffi.load("bcryptprimitives")
-- bcryptprimitives.GetAsymmetricEncryptionInterface(pszProviderName, pszAlgId, ppFunctionTable, dwFlags)
-- pszProviderName : LPCWSTR
-- pszAlgId : LPCWSTR
-- ppFunctionTable : BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out
-- dwFlags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('bcryptprimitives.dll');
const GetAsymmetricEncryptionInterface = lib.func('__stdcall', 'GetAsymmetricEncryptionInterface', 'int32_t', ['str16', 'str16', 'void *', 'uint32_t']);
// GetAsymmetricEncryptionInterface(pszProviderName, pszAlgId, ppFunctionTable, dwFlags)
// pszProviderName : LPCWSTR -> 'str16'
// pszAlgId : LPCWSTR -> 'str16'
// ppFunctionTable : BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out -> 'void *'
// dwFlags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("bcryptprimitives.dll", {
GetAsymmetricEncryptionInterface: { parameters: ["buffer", "buffer", "pointer", "u32"], result: "i32" },
});
// lib.symbols.GetAsymmetricEncryptionInterface(pszProviderName, pszAlgId, ppFunctionTable, dwFlags)
// pszProviderName : LPCWSTR -> "buffer"
// pszAlgId : LPCWSTR -> "buffer"
// ppFunctionTable : BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out -> "pointer"
// dwFlags : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetAsymmetricEncryptionInterface(
const uint16_t* pszProviderName,
const uint16_t* pszAlgId,
void* ppFunctionTable,
uint32_t dwFlags);
C, "bcryptprimitives.dll");
// $ffi->GetAsymmetricEncryptionInterface(pszProviderName, pszAlgId, ppFunctionTable, dwFlags);
// pszProviderName : LPCWSTR
// pszAlgId : LPCWSTR
// ppFunctionTable : BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out
// dwFlags : DWORD
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Bcryptprimitives extends StdCallLibrary {
Bcryptprimitives INSTANCE = Native.load("bcryptprimitives", Bcryptprimitives.class);
int GetAsymmetricEncryptionInterface(
WString pszProviderName, // LPCWSTR
WString pszAlgId, // LPCWSTR
Pointer ppFunctionTable, // BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out
int dwFlags // DWORD
);
}@[Link("bcryptprimitives")]
lib Libbcryptprimitives
fun GetAsymmetricEncryptionInterface = GetAsymmetricEncryptionInterface(
pszProviderName : UInt16*, # LPCWSTR
pszAlgId : UInt16*, # LPCWSTR
ppFunctionTable : BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE**, # BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out
dwFlags : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetAsymmetricEncryptionInterfaceNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>, Uint32);
typedef GetAsymmetricEncryptionInterfaceDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>, int);
final GetAsymmetricEncryptionInterface = DynamicLibrary.open('bcryptprimitives.dll')
.lookupFunction<GetAsymmetricEncryptionInterfaceNative, GetAsymmetricEncryptionInterfaceDart>('GetAsymmetricEncryptionInterface');
// pszProviderName : LPCWSTR -> Pointer<Utf16>
// pszAlgId : LPCWSTR -> Pointer<Utf16>
// ppFunctionTable : BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out -> Pointer<Void>
// dwFlags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetAsymmetricEncryptionInterface(
pszProviderName: PWideChar; // LPCWSTR
pszAlgId: PWideChar; // LPCWSTR
ppFunctionTable: Pointer; // BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out
dwFlags: DWORD // DWORD
): Integer; stdcall;
external 'bcryptprimitives.dll' name 'GetAsymmetricEncryptionInterface';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetAsymmetricEncryptionInterface"
c_GetAsymmetricEncryptionInterface :: CWString -> CWString -> Ptr () -> Word32 -> IO Int32
-- pszProviderName : LPCWSTR -> CWString
-- pszAlgId : LPCWSTR -> CWString
-- ppFunctionTable : BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out -> Ptr ()
-- dwFlags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getasymmetricencryptioninterface =
foreign "GetAsymmetricEncryptionInterface"
((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* pszProviderName : LPCWSTR -> (ptr uint16_t) *)
(* pszAlgId : LPCWSTR -> (ptr uint16_t) *)
(* ppFunctionTable : BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out -> (ptr void) *)
(* dwFlags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library bcryptprimitives (t "bcryptprimitives.dll"))
(cffi:use-foreign-library bcryptprimitives)
(cffi:defcfun ("GetAsymmetricEncryptionInterface" get-asymmetric-encryption-interface :convention :stdcall) :int32
(psz-provider-name (:string :encoding :utf-16le)) ; LPCWSTR
(psz-alg-id (:string :encoding :utf-16le)) ; LPCWSTR
(pp-function-table :pointer) ; BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out
(dw-flags :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetAsymmetricEncryptionInterface = Win32::API::More->new('bcryptprimitives',
'int GetAsymmetricEncryptionInterface(LPCWSTR pszProviderName, LPCWSTR pszAlgId, LPVOID ppFunctionTable, DWORD dwFlags)');
# my $ret = $GetAsymmetricEncryptionInterface->Call($pszProviderName, $pszAlgId, $ppFunctionTable, $dwFlags);
# pszProviderName : LPCWSTR -> LPCWSTR
# pszAlgId : LPCWSTR -> LPCWSTR
# ppFunctionTable : BCRYPT_ASYMMETRIC_ENCRYPTION_FUNCTION_TABLE** out -> LPVOID
# dwFlags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。