ホーム › 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 |
| hKey | HCRYPTPROV_OR_NCRYPT_KEY_HANDLE | inoptional |
| dwKeySpec | CERT_KEY_SPEC | in |
| dwFlags | CRYPT_XML_FLAGS | in |
| dwKeyInfoSpec | CRYPT_XML_KEYINFO_SPEC | in |
| pvKeyInfoSpec | void* | inoptional |
| pSignatureMethod | CRYPT_XML_ALGORITHM* | in |
| pCanonicalization | CRYPT_XML_ALGORITHM* | in |
戻り値の型: HRESULT
各言語での呼び出し定義
// 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)。