ホーム › Security.Cryptography › CryptHashSessionKey
CryptHashSessionKey
関数セッション鍵の内容をハッシュオブジェクトに追加する。
シグネチャ
// ADVAPI32.dll
#include <windows.h>
BOOL CryptHashSessionKey(
UINT_PTR hHash,
UINT_PTR hKey,
DWORD dwFlags
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||
|---|---|---|---|---|---|---|---|
| hHash | UINT_PTR | in | ハッシュオブジェクトへのハンドル。 | ||||
| hKey | UINT_PTR | in | ハッシュ対象となるキーオブジェクトへのハンドル。 | ||||
| dwFlags | DWORD | in | 次のフラグ値が定義されています。
|
戻り値の型: BOOL
公式ドキュメント
セッションキーオブジェクトの暗号ハッシュを計算します。
戻り値
関数が成功した場合、戻り値は TRUE です。
関数が失敗した場合、戻り値は FALSE です。拡張エラー情報を取得するには、 GetLastError を呼び出します。
"NTE" で始まるエラーコードは、使用している特定の CSP によって生成されます。考えられるエラーコードの一部を以下に示します。
| 戻り値 | 説明 |
|---|---|
| パラメーターのいずれかに、有効でないハンドルが指定されています。 | |
| パラメーターのいずれかに、有効でない値が含まれています。多くの場合、これは有効でないポインターです。 | |
| hHash ハンドルが、この CSP がサポートしていないアルゴリズムを指定しています。 | |
| dwFlags パラメーターが 0 以外です。 | |
| hHash パラメーターで指定されたハッシュオブジェクトが有効ではありません。 | |
| すでに「完了」とマークされているハッシュオブジェクトにデータを追加しようとしました。 | |
| キー付きハッシュアルゴリズムが使用されていますが、セッションキーがすでに有効ではありません。このエラーは、ハッシュ操作が完了する前にセッションキーが破棄された場合に生成されます。 | |
| ハッシュオブジェクトの作成時に指定された CSP コンテキストが見つかりません。 | |
| 関数が予期しない形で失敗しました。 |
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// ADVAPI32.dll
#include <windows.h>
BOOL CryptHashSessionKey(
UINT_PTR hHash,
UINT_PTR hKey,
DWORD dwFlags
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CryptHashSessionKey(
UIntPtr hHash, // UINT_PTR
UIntPtr hKey, // UINT_PTR
uint dwFlags // DWORD
);<DllImport("ADVAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CryptHashSessionKey(
hHash As UIntPtr, ' UINT_PTR
hKey As UIntPtr, ' UINT_PTR
dwFlags As UInteger ' DWORD
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hHash : UINT_PTR
' hKey : UINT_PTR
' dwFlags : DWORD
Declare PtrSafe Function CryptHashSessionKey Lib "advapi32" ( _
ByVal hHash As LongPtr, _
ByVal hKey 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
CryptHashSessionKey = ctypes.windll.advapi32.CryptHashSessionKey
CryptHashSessionKey.restype = wintypes.BOOL
CryptHashSessionKey.argtypes = [
ctypes.c_size_t, # hHash : UINT_PTR
ctypes.c_size_t, # hKey : UINT_PTR
wintypes.DWORD, # dwFlags : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
CryptHashSessionKey = Fiddle::Function.new(
lib['CryptHashSessionKey'],
[
Fiddle::TYPE_UINTPTR_T, # hHash : UINT_PTR
Fiddle::TYPE_UINTPTR_T, # hKey : UINT_PTR
-Fiddle::TYPE_INT, # dwFlags : DWORD
],
Fiddle::TYPE_INT)#[link(name = "advapi32")]
extern "system" {
fn CryptHashSessionKey(
hHash: usize, // UINT_PTR
hKey: usize, // UINT_PTR
dwFlags: u32 // DWORD
) -> 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 CryptHashSessionKey(UIntPtr hHash, UIntPtr hKey, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_CryptHashSessionKey' -Namespace Win32 -PassThru
# $api::CryptHashSessionKey(hHash, hKey, dwFlags)#uselib "ADVAPI32.dll"
#func global CryptHashSessionKey "CryptHashSessionKey" sptr, sptr, sptr
; CryptHashSessionKey hHash, hKey, dwFlags ; 戻り値は stat
; hHash : UINT_PTR -> "sptr"
; hKey : UINT_PTR -> "sptr"
; dwFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ADVAPI32.dll"
#cfunc global CryptHashSessionKey "CryptHashSessionKey" sptr, sptr, int
; res = CryptHashSessionKey(hHash, hKey, dwFlags)
; hHash : UINT_PTR -> "sptr"
; hKey : UINT_PTR -> "sptr"
; dwFlags : DWORD -> "int"; BOOL CryptHashSessionKey(UINT_PTR hHash, UINT_PTR hKey, DWORD dwFlags)
#uselib "ADVAPI32.dll"
#cfunc global CryptHashSessionKey "CryptHashSessionKey" intptr, intptr, int
; res = CryptHashSessionKey(hHash, hKey, dwFlags)
; hHash : UINT_PTR -> "intptr"
; hKey : UINT_PTR -> "intptr"
; dwFlags : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procCryptHashSessionKey = advapi32.NewProc("CryptHashSessionKey")
)
// hHash (UINT_PTR), hKey (UINT_PTR), dwFlags (DWORD)
r1, _, err := procCryptHashSessionKey.Call(
uintptr(hHash),
uintptr(hKey),
uintptr(dwFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CryptHashSessionKey(
hHash: NativeUInt; // UINT_PTR
hKey: NativeUInt; // UINT_PTR
dwFlags: DWORD // DWORD
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'CryptHashSessionKey';result := DllCall("ADVAPI32\CryptHashSessionKey"
, "UPtr", hHash ; UINT_PTR
, "UPtr", hKey ; UINT_PTR
, "UInt", dwFlags ; DWORD
, "Int") ; return: BOOL●CryptHashSessionKey(hHash, hKey, dwFlags) = DLL("ADVAPI32.dll", "bool CryptHashSessionKey(int, int, dword)")
# 呼び出し: CryptHashSessionKey(hHash, hKey, dwFlags)
# hHash : UINT_PTR -> "int"
# hKey : UINT_PTR -> "int"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "advapi32" fn CryptHashSessionKey(
hHash: usize, // UINT_PTR
hKey: usize, // UINT_PTR
dwFlags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc CryptHashSessionKey(
hHash: uint, # UINT_PTR
hKey: uint, # UINT_PTR
dwFlags: uint32 # DWORD
): int32 {.importc: "CryptHashSessionKey", stdcall, dynlib: "ADVAPI32.dll".}pragma(lib, "advapi32");
extern(Windows)
int CryptHashSessionKey(
size_t hHash, // UINT_PTR
size_t hKey, // UINT_PTR
uint dwFlags // DWORD
);ccall((:CryptHashSessionKey, "ADVAPI32.dll"), stdcall, Int32,
(Csize_t, Csize_t, UInt32),
hHash, hKey, dwFlags)
# hHash : UINT_PTR -> Csize_t
# hKey : UINT_PTR -> Csize_t
# dwFlags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t CryptHashSessionKey(
uintptr_t hHash,
uintptr_t hKey,
uint32_t dwFlags);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.CryptHashSessionKey(hHash, hKey, dwFlags)
-- hHash : UINT_PTR
-- hKey : UINT_PTR
-- dwFlags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const CryptHashSessionKey = lib.func('__stdcall', 'CryptHashSessionKey', 'int32_t', ['uintptr_t', 'uintptr_t', 'uint32_t']);
// CryptHashSessionKey(hHash, hKey, dwFlags)
// hHash : UINT_PTR -> 'uintptr_t'
// hKey : UINT_PTR -> 'uintptr_t'
// dwFlags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ADVAPI32.dll", {
CryptHashSessionKey: { parameters: ["usize", "usize", "u32"], result: "i32" },
});
// lib.symbols.CryptHashSessionKey(hHash, hKey, dwFlags)
// hHash : UINT_PTR -> "usize"
// hKey : UINT_PTR -> "usize"
// dwFlags : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CryptHashSessionKey(
size_t hHash,
size_t hKey,
uint32_t dwFlags);
C, "ADVAPI32.dll");
// $ffi->CryptHashSessionKey(hHash, hKey, dwFlags);
// hHash : UINT_PTR
// hKey : UINT_PTR
// 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 Advapi32 extends StdCallLibrary {
Advapi32 INSTANCE = Native.load("advapi32", Advapi32.class);
boolean CryptHashSessionKey(
long hHash, // UINT_PTR
long hKey, // UINT_PTR
int dwFlags // DWORD
);
}@[Link("advapi32")]
lib LibADVAPI32
fun CryptHashSessionKey = CryptHashSessionKey(
hHash : LibC::SizeT, # UINT_PTR
hKey : LibC::SizeT, # UINT_PTR
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 CryptHashSessionKeyNative = Int32 Function(UintPtr, UintPtr, Uint32);
typedef CryptHashSessionKeyDart = int Function(int, int, int);
final CryptHashSessionKey = DynamicLibrary.open('ADVAPI32.dll')
.lookupFunction<CryptHashSessionKeyNative, CryptHashSessionKeyDart>('CryptHashSessionKey');
// hHash : UINT_PTR -> UintPtr
// hKey : UINT_PTR -> UintPtr
// dwFlags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CryptHashSessionKey(
hHash: NativeUInt; // UINT_PTR
hKey: NativeUInt; // UINT_PTR
dwFlags: DWORD // DWORD
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'CryptHashSessionKey';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CryptHashSessionKey"
c_CryptHashSessionKey :: CUIntPtr -> CUIntPtr -> Word32 -> IO CInt
-- hHash : UINT_PTR -> CUIntPtr
-- hKey : UINT_PTR -> CUIntPtr
-- dwFlags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let crypthashsessionkey =
foreign "CryptHashSessionKey"
(size_t @-> size_t @-> uint32_t @-> returning int32_t)
(* hHash : UINT_PTR -> size_t *)
(* hKey : UINT_PTR -> size_t *)
(* dwFlags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)
(cffi:defcfun ("CryptHashSessionKey" crypt-hash-session-key :convention :stdcall) :int32
(h-hash :uint64) ; UINT_PTR
(h-key :uint64) ; UINT_PTR
(dw-flags :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CryptHashSessionKey = Win32::API::More->new('ADVAPI32',
'BOOL CryptHashSessionKey(WPARAM hHash, WPARAM hKey, DWORD dwFlags)');
# my $ret = $CryptHashSessionKey->Call($hHash, $hKey, $dwFlags);
# hHash : UINT_PTR -> WPARAM
# hKey : UINT_PTR -> WPARAM
# dwFlags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f CryptCreateHash — 指定アルゴリズムのハッシュオブジェクトを作成する。
- f CryptGenKey — 指定アルゴリズムの暗号鍵またはキーペアを生成する。
- f CryptHashData — ハッシュオブジェクトにデータを追加してハッシュを計算する。