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