ホーム › Security.Cryptography › CryptXmlSign
CryptXmlSign
関数鍵を用いてXMLデジタル署名を生成する。
シグネチャ
// CRYPTXML.dll
#include <windows.h>
HRESULT CryptXmlSign(
void* hSignature,
HCRYPTPROV_OR_NCRYPT_KEY_HANDLE hKey, // optional
CERT_KEY_SPEC dwKeySpec,
CRYPT_XML_FLAGS dwFlags,
CRYPT_XML_KEYINFO_SPEC dwKeyInfoSpec,
const void* pvKeyInfoSpec, // optional
const CRYPT_XML_ALGORITHM* pSignatureMethod,
const CRYPT_XML_ALGORITHM* pCanonicalization
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| hSignature | void* | in | CRYPT_XML_SIGNATURE 構造体へのハンドル。 | ||||||||
| hKey | HCRYPTPROV_OR_NCRYPT_KEY_HANDLE | inoptional | SignedInfo 要素の署名に使用される秘密鍵のハンドル。 HMAC ベースの署名アルゴリズムの場合、このパラメーターは NULL でなければなりません。 | ||||||||
| dwKeySpec | CERT_KEY_SPEC | in | 鍵の種類を指定する DWORD 値。このパラメーターには次のいずれかの値を指定できます。
| ||||||||
| dwFlags | CRYPT_XML_FLAGS | in | データの署名方法を制御する DWORD 値。このパラメーターには次のいずれかの値を指定できます。
| ||||||||
| dwKeyInfoSpec | CRYPT_XML_KEYINFO_SPEC | in | pvKeyInfoSpec パラメーターが指すデータ構造の種類。可能な組み合わせの例を以下に示します。
| ||||||||
| pvKeyInfoSpec | void* | inoptional | 構造体へのポインター。その型は dwKeyInfoSpec パラメーターの値によって決定されます。 | ||||||||
| pSignatureMethod | CRYPT_XML_ALGORITHM* | in | 署名方式を指定する CRYPT_XML_ALGORITHM 構造体へのポインター。 | ||||||||
| pCanonicalization | CRYPT_XML_ALGORITHM* | in | 正規化方式を指定する CRYPT_XML_ALGORITHM 構造体へのポインター。 |
戻り値の型: HRESULT
公式ドキュメント
SignedInfo 要素の暗号署名を作成します。
戻り値
関数が成功した場合、ゼロを返します。
関数が失敗した場合、エラーを示す HRESULT 値を返します。
解説(Remarks)
証明書が見つからない場合、CryptXmlSign は証明書選択用の UI を作成します。このウィンドウがセッション 0で実行されているプロセスから生成された場合、アプリケーションが予期せず終了する可能性があります。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// CRYPTXML.dll
#include <windows.h>
HRESULT CryptXmlSign(
void* hSignature,
HCRYPTPROV_OR_NCRYPT_KEY_HANDLE hKey, // optional
CERT_KEY_SPEC dwKeySpec,
CRYPT_XML_FLAGS dwFlags,
CRYPT_XML_KEYINFO_SPEC dwKeyInfoSpec,
const void* pvKeyInfoSpec, // optional
const CRYPT_XML_ALGORITHM* pSignatureMethod,
const CRYPT_XML_ALGORITHM* pCanonicalization
);[DllImport("CRYPTXML.dll", ExactSpelling = true)]
static extern int CryptXmlSign(
IntPtr hSignature, // void*
UIntPtr hKey, // HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
uint dwKeySpec, // CERT_KEY_SPEC
uint dwFlags, // CRYPT_XML_FLAGS
int dwKeyInfoSpec, // CRYPT_XML_KEYINFO_SPEC
IntPtr pvKeyInfoSpec, // void* optional
IntPtr pSignatureMethod, // CRYPT_XML_ALGORITHM*
IntPtr pCanonicalization // CRYPT_XML_ALGORITHM*
);<DllImport("CRYPTXML.dll", ExactSpelling:=True)>
Public Shared Function CryptXmlSign(
hSignature As IntPtr, ' void*
hKey As UIntPtr, ' HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
dwKeySpec As UInteger, ' CERT_KEY_SPEC
dwFlags As UInteger, ' CRYPT_XML_FLAGS
dwKeyInfoSpec As Integer, ' CRYPT_XML_KEYINFO_SPEC
pvKeyInfoSpec As IntPtr, ' void* optional
pSignatureMethod As IntPtr, ' CRYPT_XML_ALGORITHM*
pCanonicalization As IntPtr ' CRYPT_XML_ALGORITHM*
) As Integer
End Function' hSignature : void*
' hKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
' dwKeySpec : CERT_KEY_SPEC
' dwFlags : CRYPT_XML_FLAGS
' dwKeyInfoSpec : CRYPT_XML_KEYINFO_SPEC
' pvKeyInfoSpec : void* optional
' pSignatureMethod : CRYPT_XML_ALGORITHM*
' pCanonicalization : CRYPT_XML_ALGORITHM*
Declare PtrSafe Function CryptXmlSign Lib "cryptxml" ( _
ByVal hSignature As LongPtr, _
ByVal hKey As LongPtr, _
ByVal dwKeySpec As Long, _
ByVal dwFlags As Long, _
ByVal dwKeyInfoSpec As Long, _
ByVal pvKeyInfoSpec As LongPtr, _
ByVal pSignatureMethod As LongPtr, _
ByVal pCanonicalization As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CryptXmlSign = ctypes.windll.cryptxml.CryptXmlSign
CryptXmlSign.restype = ctypes.c_int
CryptXmlSign.argtypes = [
ctypes.POINTER(None), # hSignature : void*
ctypes.c_size_t, # hKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
wintypes.DWORD, # dwKeySpec : CERT_KEY_SPEC
wintypes.DWORD, # dwFlags : CRYPT_XML_FLAGS
ctypes.c_int, # dwKeyInfoSpec : CRYPT_XML_KEYINFO_SPEC
ctypes.POINTER(None), # pvKeyInfoSpec : void* optional
ctypes.c_void_p, # pSignatureMethod : CRYPT_XML_ALGORITHM*
ctypes.c_void_p, # pCanonicalization : CRYPT_XML_ALGORITHM*
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('CRYPTXML.dll')
CryptXmlSign = Fiddle::Function.new(
lib['CryptXmlSign'],
[
Fiddle::TYPE_VOIDP, # hSignature : void*
Fiddle::TYPE_UINTPTR_T, # hKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
-Fiddle::TYPE_INT, # dwKeySpec : CERT_KEY_SPEC
-Fiddle::TYPE_INT, # dwFlags : CRYPT_XML_FLAGS
Fiddle::TYPE_INT, # dwKeyInfoSpec : CRYPT_XML_KEYINFO_SPEC
Fiddle::TYPE_VOIDP, # pvKeyInfoSpec : void* optional
Fiddle::TYPE_VOIDP, # pSignatureMethod : CRYPT_XML_ALGORITHM*
Fiddle::TYPE_VOIDP, # pCanonicalization : CRYPT_XML_ALGORITHM*
],
Fiddle::TYPE_INT)#[link(name = "cryptxml")]
extern "system" {
fn CryptXmlSign(
hSignature: *mut (), // void*
hKey: usize, // HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
dwKeySpec: u32, // CERT_KEY_SPEC
dwFlags: u32, // CRYPT_XML_FLAGS
dwKeyInfoSpec: i32, // CRYPT_XML_KEYINFO_SPEC
pvKeyInfoSpec: *const (), // void* optional
pSignatureMethod: *const CRYPT_XML_ALGORITHM, // CRYPT_XML_ALGORITHM*
pCanonicalization: *const CRYPT_XML_ALGORITHM // CRYPT_XML_ALGORITHM*
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("CRYPTXML.dll")]
public static extern int CryptXmlSign(IntPtr hSignature, UIntPtr hKey, uint dwKeySpec, uint dwFlags, int dwKeyInfoSpec, IntPtr pvKeyInfoSpec, IntPtr pSignatureMethod, IntPtr pCanonicalization);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPTXML_CryptXmlSign' -Namespace Win32 -PassThru
# $api::CryptXmlSign(hSignature, hKey, dwKeySpec, dwFlags, dwKeyInfoSpec, pvKeyInfoSpec, pSignatureMethod, pCanonicalization)#uselib "CRYPTXML.dll"
#func global CryptXmlSign "CryptXmlSign" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; CryptXmlSign hSignature, hKey, dwKeySpec, dwFlags, dwKeyInfoSpec, pvKeyInfoSpec, varptr(pSignatureMethod), varptr(pCanonicalization) ; 戻り値は stat
; hSignature : void* -> "sptr"
; hKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> "sptr"
; dwKeySpec : CERT_KEY_SPEC -> "sptr"
; dwFlags : CRYPT_XML_FLAGS -> "sptr"
; dwKeyInfoSpec : CRYPT_XML_KEYINFO_SPEC -> "sptr"
; pvKeyInfoSpec : void* optional -> "sptr"
; pSignatureMethod : CRYPT_XML_ALGORITHM* -> "sptr"
; pCanonicalization : CRYPT_XML_ALGORITHM* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "CRYPTXML.dll" #cfunc global CryptXmlSign "CryptXmlSign" sptr, sptr, int, int, int, sptr, var, var ; res = CryptXmlSign(hSignature, hKey, dwKeySpec, dwFlags, dwKeyInfoSpec, pvKeyInfoSpec, pSignatureMethod, pCanonicalization) ; hSignature : void* -> "sptr" ; hKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> "sptr" ; dwKeySpec : CERT_KEY_SPEC -> "int" ; dwFlags : CRYPT_XML_FLAGS -> "int" ; dwKeyInfoSpec : CRYPT_XML_KEYINFO_SPEC -> "int" ; pvKeyInfoSpec : void* optional -> "sptr" ; pSignatureMethod : CRYPT_XML_ALGORITHM* -> "var" ; pCanonicalization : CRYPT_XML_ALGORITHM* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "CRYPTXML.dll" #cfunc global CryptXmlSign "CryptXmlSign" sptr, sptr, int, int, int, sptr, sptr, sptr ; res = CryptXmlSign(hSignature, hKey, dwKeySpec, dwFlags, dwKeyInfoSpec, pvKeyInfoSpec, varptr(pSignatureMethod), varptr(pCanonicalization)) ; hSignature : void* -> "sptr" ; hKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> "sptr" ; dwKeySpec : CERT_KEY_SPEC -> "int" ; dwFlags : CRYPT_XML_FLAGS -> "int" ; dwKeyInfoSpec : CRYPT_XML_KEYINFO_SPEC -> "int" ; pvKeyInfoSpec : void* optional -> "sptr" ; pSignatureMethod : CRYPT_XML_ALGORITHM* -> "sptr" ; pCanonicalization : CRYPT_XML_ALGORITHM* -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT CryptXmlSign(void* hSignature, HCRYPTPROV_OR_NCRYPT_KEY_HANDLE hKey, CERT_KEY_SPEC dwKeySpec, CRYPT_XML_FLAGS dwFlags, CRYPT_XML_KEYINFO_SPEC dwKeyInfoSpec, void* pvKeyInfoSpec, CRYPT_XML_ALGORITHM* pSignatureMethod, CRYPT_XML_ALGORITHM* pCanonicalization) #uselib "CRYPTXML.dll" #cfunc global CryptXmlSign "CryptXmlSign" intptr, intptr, int, int, int, intptr, var, var ; res = CryptXmlSign(hSignature, hKey, dwKeySpec, dwFlags, dwKeyInfoSpec, pvKeyInfoSpec, pSignatureMethod, pCanonicalization) ; hSignature : void* -> "intptr" ; hKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> "intptr" ; dwKeySpec : CERT_KEY_SPEC -> "int" ; dwFlags : CRYPT_XML_FLAGS -> "int" ; dwKeyInfoSpec : CRYPT_XML_KEYINFO_SPEC -> "int" ; pvKeyInfoSpec : void* optional -> "intptr" ; pSignatureMethod : CRYPT_XML_ALGORITHM* -> "var" ; pCanonicalization : CRYPT_XML_ALGORITHM* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT CryptXmlSign(void* hSignature, HCRYPTPROV_OR_NCRYPT_KEY_HANDLE hKey, CERT_KEY_SPEC dwKeySpec, CRYPT_XML_FLAGS dwFlags, CRYPT_XML_KEYINFO_SPEC dwKeyInfoSpec, void* pvKeyInfoSpec, CRYPT_XML_ALGORITHM* pSignatureMethod, CRYPT_XML_ALGORITHM* pCanonicalization) #uselib "CRYPTXML.dll" #cfunc global CryptXmlSign "CryptXmlSign" intptr, intptr, int, int, int, intptr, intptr, intptr ; res = CryptXmlSign(hSignature, hKey, dwKeySpec, dwFlags, dwKeyInfoSpec, pvKeyInfoSpec, varptr(pSignatureMethod), varptr(pCanonicalization)) ; hSignature : void* -> "intptr" ; hKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> "intptr" ; dwKeySpec : CERT_KEY_SPEC -> "int" ; dwFlags : CRYPT_XML_FLAGS -> "int" ; dwKeyInfoSpec : CRYPT_XML_KEYINFO_SPEC -> "int" ; pvKeyInfoSpec : void* optional -> "intptr" ; pSignatureMethod : CRYPT_XML_ALGORITHM* -> "intptr" ; pCanonicalization : CRYPT_XML_ALGORITHM* -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
cryptxml = windows.NewLazySystemDLL("CRYPTXML.dll")
procCryptXmlSign = cryptxml.NewProc("CryptXmlSign")
)
// hSignature (void*), hKey (HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional), dwKeySpec (CERT_KEY_SPEC), dwFlags (CRYPT_XML_FLAGS), dwKeyInfoSpec (CRYPT_XML_KEYINFO_SPEC), pvKeyInfoSpec (void* optional), pSignatureMethod (CRYPT_XML_ALGORITHM*), pCanonicalization (CRYPT_XML_ALGORITHM*)
r1, _, err := procCryptXmlSign.Call(
uintptr(hSignature),
uintptr(hKey),
uintptr(dwKeySpec),
uintptr(dwFlags),
uintptr(dwKeyInfoSpec),
uintptr(pvKeyInfoSpec),
uintptr(pSignatureMethod),
uintptr(pCanonicalization),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction CryptXmlSign(
hSignature: Pointer; // void*
hKey: NativeUInt; // HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
dwKeySpec: DWORD; // CERT_KEY_SPEC
dwFlags: DWORD; // CRYPT_XML_FLAGS
dwKeyInfoSpec: Integer; // CRYPT_XML_KEYINFO_SPEC
pvKeyInfoSpec: Pointer; // void* optional
pSignatureMethod: Pointer; // CRYPT_XML_ALGORITHM*
pCanonicalization: Pointer // CRYPT_XML_ALGORITHM*
): Integer; stdcall;
external 'CRYPTXML.dll' name 'CryptXmlSign';result := DllCall("CRYPTXML\CryptXmlSign"
, "Ptr", hSignature ; void*
, "UPtr", hKey ; HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
, "UInt", dwKeySpec ; CERT_KEY_SPEC
, "UInt", dwFlags ; CRYPT_XML_FLAGS
, "Int", dwKeyInfoSpec ; CRYPT_XML_KEYINFO_SPEC
, "Ptr", pvKeyInfoSpec ; void* optional
, "Ptr", pSignatureMethod ; CRYPT_XML_ALGORITHM*
, "Ptr", pCanonicalization ; CRYPT_XML_ALGORITHM*
, "Int") ; return: HRESULT●CryptXmlSign(hSignature, hKey, dwKeySpec, dwFlags, dwKeyInfoSpec, pvKeyInfoSpec, pSignatureMethod, pCanonicalization) = DLL("CRYPTXML.dll", "int CryptXmlSign(void*, int, dword, dword, int, void*, void*, void*)")
# 呼び出し: CryptXmlSign(hSignature, hKey, dwKeySpec, dwFlags, dwKeyInfoSpec, pvKeyInfoSpec, pSignatureMethod, pCanonicalization)
# hSignature : void* -> "void*"
# hKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> "int"
# dwKeySpec : CERT_KEY_SPEC -> "dword"
# dwFlags : CRYPT_XML_FLAGS -> "dword"
# dwKeyInfoSpec : CRYPT_XML_KEYINFO_SPEC -> "int"
# pvKeyInfoSpec : void* optional -> "void*"
# pSignatureMethod : CRYPT_XML_ALGORITHM* -> "void*"
# pCanonicalization : CRYPT_XML_ALGORITHM* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "cryptxml" fn CryptXmlSign(
hSignature: ?*anyopaque, // void*
hKey: usize, // HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
dwKeySpec: u32, // CERT_KEY_SPEC
dwFlags: u32, // CRYPT_XML_FLAGS
dwKeyInfoSpec: i32, // CRYPT_XML_KEYINFO_SPEC
pvKeyInfoSpec: ?*anyopaque, // void* optional
pSignatureMethod: [*c]CRYPT_XML_ALGORITHM, // CRYPT_XML_ALGORITHM*
pCanonicalization: [*c]CRYPT_XML_ALGORITHM // CRYPT_XML_ALGORITHM*
) callconv(std.os.windows.WINAPI) i32;proc CryptXmlSign(
hSignature: pointer, # void*
hKey: uint, # HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
dwKeySpec: uint32, # CERT_KEY_SPEC
dwFlags: uint32, # CRYPT_XML_FLAGS
dwKeyInfoSpec: int32, # CRYPT_XML_KEYINFO_SPEC
pvKeyInfoSpec: pointer, # void* optional
pSignatureMethod: ptr CRYPT_XML_ALGORITHM, # CRYPT_XML_ALGORITHM*
pCanonicalization: ptr CRYPT_XML_ALGORITHM # CRYPT_XML_ALGORITHM*
): int32 {.importc: "CryptXmlSign", stdcall, dynlib: "CRYPTXML.dll".}pragma(lib, "cryptxml");
extern(Windows)
int CryptXmlSign(
void* hSignature, // void*
size_t hKey, // HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
uint dwKeySpec, // CERT_KEY_SPEC
uint dwFlags, // CRYPT_XML_FLAGS
int dwKeyInfoSpec, // CRYPT_XML_KEYINFO_SPEC
void* pvKeyInfoSpec, // void* optional
CRYPT_XML_ALGORITHM* pSignatureMethod, // CRYPT_XML_ALGORITHM*
CRYPT_XML_ALGORITHM* pCanonicalization // CRYPT_XML_ALGORITHM*
);ccall((:CryptXmlSign, "CRYPTXML.dll"), stdcall, Int32,
(Ptr{Cvoid}, Csize_t, UInt32, UInt32, Int32, Ptr{Cvoid}, Ptr{CRYPT_XML_ALGORITHM}, Ptr{CRYPT_XML_ALGORITHM}),
hSignature, hKey, dwKeySpec, dwFlags, dwKeyInfoSpec, pvKeyInfoSpec, pSignatureMethod, pCanonicalization)
# hSignature : void* -> Ptr{Cvoid}
# hKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> Csize_t
# dwKeySpec : CERT_KEY_SPEC -> UInt32
# dwFlags : CRYPT_XML_FLAGS -> UInt32
# dwKeyInfoSpec : CRYPT_XML_KEYINFO_SPEC -> Int32
# pvKeyInfoSpec : void* optional -> Ptr{Cvoid}
# pSignatureMethod : CRYPT_XML_ALGORITHM* -> Ptr{CRYPT_XML_ALGORITHM}
# pCanonicalization : CRYPT_XML_ALGORITHM* -> Ptr{CRYPT_XML_ALGORITHM}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t CryptXmlSign(
void* hSignature,
uintptr_t hKey,
uint32_t dwKeySpec,
uint32_t dwFlags,
int32_t dwKeyInfoSpec,
void* pvKeyInfoSpec,
void* pSignatureMethod,
void* pCanonicalization);
]]
local cryptxml = ffi.load("cryptxml")
-- cryptxml.CryptXmlSign(hSignature, hKey, dwKeySpec, dwFlags, dwKeyInfoSpec, pvKeyInfoSpec, pSignatureMethod, pCanonicalization)
-- hSignature : void*
-- hKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
-- dwKeySpec : CERT_KEY_SPEC
-- dwFlags : CRYPT_XML_FLAGS
-- dwKeyInfoSpec : CRYPT_XML_KEYINFO_SPEC
-- pvKeyInfoSpec : void* optional
-- pSignatureMethod : CRYPT_XML_ALGORITHM*
-- pCanonicalization : CRYPT_XML_ALGORITHM*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('CRYPTXML.dll');
const CryptXmlSign = lib.func('__stdcall', 'CryptXmlSign', 'int32_t', ['void *', 'uintptr_t', 'uint32_t', 'uint32_t', 'int32_t', 'void *', 'void *', 'void *']);
// CryptXmlSign(hSignature, hKey, dwKeySpec, dwFlags, dwKeyInfoSpec, pvKeyInfoSpec, pSignatureMethod, pCanonicalization)
// hSignature : void* -> 'void *'
// hKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> 'uintptr_t'
// dwKeySpec : CERT_KEY_SPEC -> 'uint32_t'
// dwFlags : CRYPT_XML_FLAGS -> 'uint32_t'
// dwKeyInfoSpec : CRYPT_XML_KEYINFO_SPEC -> 'int32_t'
// pvKeyInfoSpec : void* optional -> 'void *'
// pSignatureMethod : CRYPT_XML_ALGORITHM* -> 'void *'
// pCanonicalization : CRYPT_XML_ALGORITHM* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("CRYPTXML.dll", {
CryptXmlSign: { parameters: ["pointer", "usize", "u32", "u32", "i32", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.CryptXmlSign(hSignature, hKey, dwKeySpec, dwFlags, dwKeyInfoSpec, pvKeyInfoSpec, pSignatureMethod, pCanonicalization)
// hSignature : void* -> "pointer"
// hKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> "usize"
// dwKeySpec : CERT_KEY_SPEC -> "u32"
// dwFlags : CRYPT_XML_FLAGS -> "u32"
// dwKeyInfoSpec : CRYPT_XML_KEYINFO_SPEC -> "i32"
// pvKeyInfoSpec : void* optional -> "pointer"
// pSignatureMethod : CRYPT_XML_ALGORITHM* -> "pointer"
// pCanonicalization : CRYPT_XML_ALGORITHM* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CryptXmlSign(
void* hSignature,
size_t hKey,
uint32_t dwKeySpec,
uint32_t dwFlags,
int32_t dwKeyInfoSpec,
void* pvKeyInfoSpec,
void* pSignatureMethod,
void* pCanonicalization);
C, "CRYPTXML.dll");
// $ffi->CryptXmlSign(hSignature, hKey, dwKeySpec, dwFlags, dwKeyInfoSpec, pvKeyInfoSpec, pSignatureMethod, pCanonicalization);
// hSignature : void*
// hKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
// dwKeySpec : CERT_KEY_SPEC
// dwFlags : CRYPT_XML_FLAGS
// dwKeyInfoSpec : CRYPT_XML_KEYINFO_SPEC
// pvKeyInfoSpec : void* optional
// pSignatureMethod : CRYPT_XML_ALGORITHM*
// pCanonicalization : CRYPT_XML_ALGORITHM*
// 構造体/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 Cryptxml extends StdCallLibrary {
Cryptxml INSTANCE = Native.load("cryptxml", Cryptxml.class);
int CryptXmlSign(
Pointer hSignature, // void*
long hKey, // HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
int dwKeySpec, // CERT_KEY_SPEC
int dwFlags, // CRYPT_XML_FLAGS
int dwKeyInfoSpec, // CRYPT_XML_KEYINFO_SPEC
Pointer pvKeyInfoSpec, // void* optional
Pointer pSignatureMethod, // CRYPT_XML_ALGORITHM*
Pointer pCanonicalization // CRYPT_XML_ALGORITHM*
);
}@[Link("cryptxml")]
lib LibCRYPTXML
fun CryptXmlSign = CryptXmlSign(
hSignature : Void*, # void*
hKey : LibC::SizeT, # HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
dwKeySpec : UInt32, # CERT_KEY_SPEC
dwFlags : UInt32, # CRYPT_XML_FLAGS
dwKeyInfoSpec : Int32, # CRYPT_XML_KEYINFO_SPEC
pvKeyInfoSpec : Void*, # void* optional
pSignatureMethod : CRYPT_XML_ALGORITHM*, # CRYPT_XML_ALGORITHM*
pCanonicalization : CRYPT_XML_ALGORITHM* # CRYPT_XML_ALGORITHM*
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CryptXmlSignNative = Int32 Function(Pointer<Void>, UintPtr, Uint32, Uint32, Int32, Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef CryptXmlSignDart = int Function(Pointer<Void>, int, int, int, int, Pointer<Void>, Pointer<Void>, Pointer<Void>);
final CryptXmlSign = DynamicLibrary.open('CRYPTXML.dll')
.lookupFunction<CryptXmlSignNative, CryptXmlSignDart>('CryptXmlSign');
// hSignature : void* -> Pointer<Void>
// hKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> UintPtr
// dwKeySpec : CERT_KEY_SPEC -> Uint32
// dwFlags : CRYPT_XML_FLAGS -> Uint32
// dwKeyInfoSpec : CRYPT_XML_KEYINFO_SPEC -> Int32
// pvKeyInfoSpec : void* optional -> Pointer<Void>
// pSignatureMethod : CRYPT_XML_ALGORITHM* -> Pointer<Void>
// pCanonicalization : CRYPT_XML_ALGORITHM* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CryptXmlSign(
hSignature: Pointer; // void*
hKey: NativeUInt; // HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
dwKeySpec: DWORD; // CERT_KEY_SPEC
dwFlags: DWORD; // CRYPT_XML_FLAGS
dwKeyInfoSpec: Integer; // CRYPT_XML_KEYINFO_SPEC
pvKeyInfoSpec: Pointer; // void* optional
pSignatureMethod: Pointer; // CRYPT_XML_ALGORITHM*
pCanonicalization: Pointer // CRYPT_XML_ALGORITHM*
): Integer; stdcall;
external 'CRYPTXML.dll' name 'CryptXmlSign';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CryptXmlSign"
c_CryptXmlSign :: Ptr () -> CUIntPtr -> Word32 -> Word32 -> Int32 -> Ptr () -> Ptr () -> Ptr () -> IO Int32
-- hSignature : void* -> Ptr ()
-- hKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> CUIntPtr
-- dwKeySpec : CERT_KEY_SPEC -> Word32
-- dwFlags : CRYPT_XML_FLAGS -> Word32
-- dwKeyInfoSpec : CRYPT_XML_KEYINFO_SPEC -> Int32
-- pvKeyInfoSpec : void* optional -> Ptr ()
-- pSignatureMethod : CRYPT_XML_ALGORITHM* -> Ptr ()
-- pCanonicalization : CRYPT_XML_ALGORITHM* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let cryptxmlsign =
foreign "CryptXmlSign"
((ptr void) @-> size_t @-> uint32_t @-> uint32_t @-> int32_t @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* hSignature : void* -> (ptr void) *)
(* hKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> size_t *)
(* dwKeySpec : CERT_KEY_SPEC -> uint32_t *)
(* dwFlags : CRYPT_XML_FLAGS -> uint32_t *)
(* dwKeyInfoSpec : CRYPT_XML_KEYINFO_SPEC -> int32_t *)
(* pvKeyInfoSpec : void* optional -> (ptr void) *)
(* pSignatureMethod : CRYPT_XML_ALGORITHM* -> (ptr void) *)
(* pCanonicalization : CRYPT_XML_ALGORITHM* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library cryptxml (t "CRYPTXML.dll"))
(cffi:use-foreign-library cryptxml)
(cffi:defcfun ("CryptXmlSign" crypt-xml-sign :convention :stdcall) :int32
(h-signature :pointer) ; void*
(h-key :uint64) ; HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
(dw-key-spec :uint32) ; CERT_KEY_SPEC
(dw-flags :uint32) ; CRYPT_XML_FLAGS
(dw-key-info-spec :int32) ; CRYPT_XML_KEYINFO_SPEC
(pv-key-info-spec :pointer) ; void* optional
(p-signature-method :pointer) ; CRYPT_XML_ALGORITHM*
(p-canonicalization :pointer)) ; CRYPT_XML_ALGORITHM*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CryptXmlSign = Win32::API::More->new('CRYPTXML',
'int CryptXmlSign(LPVOID hSignature, WPARAM hKey, DWORD dwKeySpec, DWORD dwFlags, int dwKeyInfoSpec, LPVOID pvKeyInfoSpec, LPVOID pSignatureMethod, LPVOID pCanonicalization)');
# my $ret = $CryptXmlSign->Call($hSignature, $hKey, $dwKeySpec, $dwFlags, $dwKeyInfoSpec, $pvKeyInfoSpec, $pSignatureMethod, $pCanonicalization);
# hSignature : void* -> LPVOID
# hKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> WPARAM
# dwKeySpec : CERT_KEY_SPEC -> DWORD
# dwFlags : CRYPT_XML_FLAGS -> DWORD
# dwKeyInfoSpec : CRYPT_XML_KEYINFO_SPEC -> int
# pvKeyInfoSpec : void* optional -> LPVOID
# pSignatureMethod : CRYPT_XML_ALGORITHM* -> LPVOID
# pCanonicalization : CRYPT_XML_ALGORITHM* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。