ホーム › Security.Cryptography › BCryptOpenAlgorithmProvider
BCryptOpenAlgorithmProvider
関数CNGの指定アルゴリズムプロバイダーを開いてハンドルを取得する。
シグネチャ
// bcrypt.dll
#include <windows.h>
NTSTATUS BCryptOpenAlgorithmProvider(
BCRYPT_ALG_HANDLE* phAlgorithm,
LPCWSTR pszAlgId,
LPCWSTR pszImplementation, // optional
BCRYPT_OPEN_ALGORITHM_PROVIDER_FLAGS dwFlags
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| phAlgorithm | BCRYPT_ALG_HANDLE* | out |
| pszAlgId | LPCWSTR | in |
| pszImplementation | LPCWSTR | inoptional |
| dwFlags | BCRYPT_OPEN_ALGORITHM_PROVIDER_FLAGS | in |
戻り値の型: NTSTATUS
各言語での呼び出し定義
// bcrypt.dll
#include <windows.h>
NTSTATUS BCryptOpenAlgorithmProvider(
BCRYPT_ALG_HANDLE* phAlgorithm,
LPCWSTR pszAlgId,
LPCWSTR pszImplementation, // optional
BCRYPT_OPEN_ALGORITHM_PROVIDER_FLAGS dwFlags
);[DllImport("bcrypt.dll", ExactSpelling = true)]
static extern int BCryptOpenAlgorithmProvider(
IntPtr phAlgorithm, // BCRYPT_ALG_HANDLE* out
[MarshalAs(UnmanagedType.LPWStr)] string pszAlgId, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string pszImplementation, // LPCWSTR optional
uint dwFlags // BCRYPT_OPEN_ALGORITHM_PROVIDER_FLAGS
);<DllImport("bcrypt.dll", ExactSpelling:=True)>
Public Shared Function BCryptOpenAlgorithmProvider(
phAlgorithm As IntPtr, ' BCRYPT_ALG_HANDLE* out
<MarshalAs(UnmanagedType.LPWStr)> pszAlgId As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> pszImplementation As String, ' LPCWSTR optional
dwFlags As UInteger ' BCRYPT_OPEN_ALGORITHM_PROVIDER_FLAGS
) As Integer
End Function' phAlgorithm : BCRYPT_ALG_HANDLE* out
' pszAlgId : LPCWSTR
' pszImplementation : LPCWSTR optional
' dwFlags : BCRYPT_OPEN_ALGORITHM_PROVIDER_FLAGS
Declare PtrSafe Function BCryptOpenAlgorithmProvider Lib "bcrypt" ( _
ByVal phAlgorithm As LongPtr, _
ByVal pszAlgId As LongPtr, _
ByVal pszImplementation 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
BCryptOpenAlgorithmProvider = ctypes.windll.bcrypt.BCryptOpenAlgorithmProvider
BCryptOpenAlgorithmProvider.restype = ctypes.c_int
BCryptOpenAlgorithmProvider.argtypes = [
ctypes.c_void_p, # phAlgorithm : BCRYPT_ALG_HANDLE* out
wintypes.LPCWSTR, # pszAlgId : LPCWSTR
wintypes.LPCWSTR, # pszImplementation : LPCWSTR optional
wintypes.DWORD, # dwFlags : BCRYPT_OPEN_ALGORITHM_PROVIDER_FLAGS
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('bcrypt.dll')
BCryptOpenAlgorithmProvider = Fiddle::Function.new(
lib['BCryptOpenAlgorithmProvider'],
[
Fiddle::TYPE_VOIDP, # phAlgorithm : BCRYPT_ALG_HANDLE* out
Fiddle::TYPE_VOIDP, # pszAlgId : LPCWSTR
Fiddle::TYPE_VOIDP, # pszImplementation : LPCWSTR optional
-Fiddle::TYPE_INT, # dwFlags : BCRYPT_OPEN_ALGORITHM_PROVIDER_FLAGS
],
Fiddle::TYPE_INT)#[link(name = "bcrypt")]
extern "system" {
fn BCryptOpenAlgorithmProvider(
phAlgorithm: *mut *mut core::ffi::c_void, // BCRYPT_ALG_HANDLE* out
pszAlgId: *const u16, // LPCWSTR
pszImplementation: *const u16, // LPCWSTR optional
dwFlags: u32 // BCRYPT_OPEN_ALGORITHM_PROVIDER_FLAGS
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("bcrypt.dll")]
public static extern int BCryptOpenAlgorithmProvider(IntPtr phAlgorithm, [MarshalAs(UnmanagedType.LPWStr)] string pszAlgId, [MarshalAs(UnmanagedType.LPWStr)] string pszImplementation, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'bcrypt_BCryptOpenAlgorithmProvider' -Namespace Win32 -PassThru
# $api::BCryptOpenAlgorithmProvider(phAlgorithm, pszAlgId, pszImplementation, dwFlags)#uselib "bcrypt.dll"
#func global BCryptOpenAlgorithmProvider "BCryptOpenAlgorithmProvider" sptr, sptr, sptr, sptr
; BCryptOpenAlgorithmProvider phAlgorithm, pszAlgId, pszImplementation, dwFlags ; 戻り値は stat
; phAlgorithm : BCRYPT_ALG_HANDLE* out -> "sptr"
; pszAlgId : LPCWSTR -> "sptr"
; pszImplementation : LPCWSTR optional -> "sptr"
; dwFlags : BCRYPT_OPEN_ALGORITHM_PROVIDER_FLAGS -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "bcrypt.dll"
#cfunc global BCryptOpenAlgorithmProvider "BCryptOpenAlgorithmProvider" sptr, wstr, wstr, int
; res = BCryptOpenAlgorithmProvider(phAlgorithm, pszAlgId, pszImplementation, dwFlags)
; phAlgorithm : BCRYPT_ALG_HANDLE* out -> "sptr"
; pszAlgId : LPCWSTR -> "wstr"
; pszImplementation : LPCWSTR optional -> "wstr"
; dwFlags : BCRYPT_OPEN_ALGORITHM_PROVIDER_FLAGS -> "int"; NTSTATUS BCryptOpenAlgorithmProvider(BCRYPT_ALG_HANDLE* phAlgorithm, LPCWSTR pszAlgId, LPCWSTR pszImplementation, BCRYPT_OPEN_ALGORITHM_PROVIDER_FLAGS dwFlags)
#uselib "bcrypt.dll"
#cfunc global BCryptOpenAlgorithmProvider "BCryptOpenAlgorithmProvider" intptr, wstr, wstr, int
; res = BCryptOpenAlgorithmProvider(phAlgorithm, pszAlgId, pszImplementation, dwFlags)
; phAlgorithm : BCRYPT_ALG_HANDLE* out -> "intptr"
; pszAlgId : LPCWSTR -> "wstr"
; pszImplementation : LPCWSTR optional -> "wstr"
; dwFlags : BCRYPT_OPEN_ALGORITHM_PROVIDER_FLAGS -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
bcrypt = windows.NewLazySystemDLL("bcrypt.dll")
procBCryptOpenAlgorithmProvider = bcrypt.NewProc("BCryptOpenAlgorithmProvider")
)
// phAlgorithm (BCRYPT_ALG_HANDLE* out), pszAlgId (LPCWSTR), pszImplementation (LPCWSTR optional), dwFlags (BCRYPT_OPEN_ALGORITHM_PROVIDER_FLAGS)
r1, _, err := procBCryptOpenAlgorithmProvider.Call(
uintptr(phAlgorithm),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszAlgId))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszImplementation))),
uintptr(dwFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // NTSTATUSfunction BCryptOpenAlgorithmProvider(
phAlgorithm: Pointer; // BCRYPT_ALG_HANDLE* out
pszAlgId: PWideChar; // LPCWSTR
pszImplementation: PWideChar; // LPCWSTR optional
dwFlags: DWORD // BCRYPT_OPEN_ALGORITHM_PROVIDER_FLAGS
): Integer; stdcall;
external 'bcrypt.dll' name 'BCryptOpenAlgorithmProvider';result := DllCall("bcrypt\BCryptOpenAlgorithmProvider"
, "Ptr", phAlgorithm ; BCRYPT_ALG_HANDLE* out
, "WStr", pszAlgId ; LPCWSTR
, "WStr", pszImplementation ; LPCWSTR optional
, "UInt", dwFlags ; BCRYPT_OPEN_ALGORITHM_PROVIDER_FLAGS
, "Int") ; return: NTSTATUS●BCryptOpenAlgorithmProvider(phAlgorithm, pszAlgId, pszImplementation, dwFlags) = DLL("bcrypt.dll", "int BCryptOpenAlgorithmProvider(void*, char*, char*, dword)")
# 呼び出し: BCryptOpenAlgorithmProvider(phAlgorithm, pszAlgId, pszImplementation, dwFlags)
# phAlgorithm : BCRYPT_ALG_HANDLE* out -> "void*"
# pszAlgId : LPCWSTR -> "char*"
# pszImplementation : LPCWSTR optional -> "char*"
# dwFlags : BCRYPT_OPEN_ALGORITHM_PROVIDER_FLAGS -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。