CryptSignAndEncodeCertificate
関数シグネチャ
// CRYPT32.dll
#include <windows.h>
BOOL CryptSignAndEncodeCertificate(
HCRYPTPROV_OR_NCRYPT_KEY_HANDLE hCryptProvOrNCryptKey, // optional
CERT_KEY_SPEC dwKeySpec, // optional
CERT_QUERY_ENCODING_TYPE dwCertEncodingType,
LPCSTR lpszStructType,
const void* pvStructInfo,
CRYPT_ALGORITHM_IDENTIFIER* pSignatureAlgorithm,
const void* pvHashAuxInfo, // optional
BYTE* pbEncoded, // optional
DWORD* pcbEncoded
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hCryptProvOrNCryptKey | HCRYPTPROV_OR_NCRYPT_KEY_HANDLE | inoptional | 署名に使うCSPまたはCNGキーのハンドル。秘密鍵を保持するプロバイダーを指す。 | ||||||||||
| dwKeySpec | CERT_KEY_SPEC | inoptional | プロバイダーのコンテナーから使用する 秘密キー を指定します。次のいずれかの値を指定する必要があります。hCryptProvOrNCryptKey パラメーターで CNG キーが渡された場合、このパラメーターは無視されます。
| ||||||||||
| dwCertEncodingType | CERT_QUERY_ENCODING_TYPE | in | 使用するエンコードの種類を指定します。次の値を指定できます。
| ||||||||||
| lpszStructType | LPCSTR | in | エンコードして署名するデータの種類を含む、null で終わる ANSI 文字列へのポインターです。エンコード操作では、次の定義済み lpszStructType 定数が使用されます。
| ||||||||||
| pvStructInfo | void* | in | 署名およびエンコードするデータを含む構造体のアドレスです。この構造体の形式は lpszStructType パラメーターによって決まります。 | ||||||||||
| pSignatureAlgorithm | CRYPT_ALGORITHM_IDENTIFIER* | in | 署名アルゴリズムの オブジェクト識別子 (OID) と必要な追加パラメーターを含む CRYPT_ALGORITHM_IDENTIFIER 構造体へのポインターです。この関数は次のアルゴリズム OID を使用します。
| ||||||||||
| pvHashAuxInfo | void* | inoptional | 予約されています。NULL である必要があります。 | ||||||||||
| pbEncoded | BYTE* | outoptional | 署名およびエンコードされた出力を受け取るバッファーへのポインターです。 このパラメーターは、メモリ割り当てのためにこの情報のサイズを設定する目的で NULL にできます。詳細については、Retrieving Data of Unknown Length を参照してください。 | ||||||||||
| pcbEncoded | DWORD* | inout | pbEncoded パラメーターが指すバッファーのサイズ (バイト単位) を含む DWORD へのポインターです。関数が返るとき、この DWORD にはバッファーに格納された、または格納されるバイト数が入ります。 注 バッファーで返されたデータを処理する際、アプリケーションは返されたデータの実際のサイズを使用する必要があります。実際のサイズは、入力時に指定したバッファーのサイズよりわずかに小さい場合があります。(入力時には、出力されうる最大のデータが収まるように、通常は十分大きいバッファーサイズが指定されます。) 出力時には、このパラメーターが指す変数が、バッファーにコピーされたデータの実際のサイズを反映するように更新されます。
|
戻り値の型: BOOL
公式ドキュメント
証明書、証明書失効リスト (CRL)、証明書信頼リスト (CTL)、または証明書要求をエンコードして署名します。
戻り値
関数が成功した場合、戻り値は 0 以外 (TRUE) です。
関数が失敗した場合、戻り値は 0 (FALSE) です。拡張エラー情報を取得するには、GetLastError を呼び出します。
| 戻り値 | 説明 |
|---|---|
| pbEncoded パラメーターで指定されたバッファーが、返されるデータを保持するのに十分な大きさでない場合、関数は ERROR_MORE_DATA コードを設定し、必要なバッファーサイズ (バイト単位) を pcbEncoded が指す変数に格納します。 | |
| 無効な証明書エンコードの種類です。現在は X509_ASN_ENCODING のみがサポートされています。 | |
| 署名アルゴリズムの OID が、既知またはサポートされているハッシュアルゴリズムに対応していません。 | |
| エンコードまたはデコード中にエラーが発生しました。このエラーの最も可能性が高い原因は、pvStructInfo が指す構造体のフィールドが正しく初期化されていないことです。 |
関数が失敗した場合、GetLastError は Abstract Syntax Notation One (ASN.1) のエンコード/デコードエラーを返すことがあります。これらのエラーの詳細については、ASN.1 Encoding/Decoding Return Values を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// CRYPT32.dll
#include <windows.h>
BOOL CryptSignAndEncodeCertificate(
HCRYPTPROV_OR_NCRYPT_KEY_HANDLE hCryptProvOrNCryptKey, // optional
CERT_KEY_SPEC dwKeySpec, // optional
CERT_QUERY_ENCODING_TYPE dwCertEncodingType,
LPCSTR lpszStructType,
const void* pvStructInfo,
CRYPT_ALGORITHM_IDENTIFIER* pSignatureAlgorithm,
const void* pvHashAuxInfo, // optional
BYTE* pbEncoded, // optional
DWORD* pcbEncoded
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CryptSignAndEncodeCertificate(
UIntPtr hCryptProvOrNCryptKey, // HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
uint dwKeySpec, // CERT_KEY_SPEC optional
uint dwCertEncodingType, // CERT_QUERY_ENCODING_TYPE
[MarshalAs(UnmanagedType.LPStr)] string lpszStructType, // LPCSTR
IntPtr pvStructInfo, // void*
IntPtr pSignatureAlgorithm, // CRYPT_ALGORITHM_IDENTIFIER*
IntPtr pvHashAuxInfo, // void* optional
IntPtr pbEncoded, // BYTE* optional, out
ref uint pcbEncoded // DWORD* in/out
);<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CryptSignAndEncodeCertificate(
hCryptProvOrNCryptKey As UIntPtr, ' HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
dwKeySpec As UInteger, ' CERT_KEY_SPEC optional
dwCertEncodingType As UInteger, ' CERT_QUERY_ENCODING_TYPE
<MarshalAs(UnmanagedType.LPStr)> lpszStructType As String, ' LPCSTR
pvStructInfo As IntPtr, ' void*
pSignatureAlgorithm As IntPtr, ' CRYPT_ALGORITHM_IDENTIFIER*
pvHashAuxInfo As IntPtr, ' void* optional
pbEncoded As IntPtr, ' BYTE* optional, out
ByRef pcbEncoded As UInteger ' DWORD* in/out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hCryptProvOrNCryptKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
' dwKeySpec : CERT_KEY_SPEC optional
' dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
' lpszStructType : LPCSTR
' pvStructInfo : void*
' pSignatureAlgorithm : CRYPT_ALGORITHM_IDENTIFIER*
' pvHashAuxInfo : void* optional
' pbEncoded : BYTE* optional, out
' pcbEncoded : DWORD* in/out
Declare PtrSafe Function CryptSignAndEncodeCertificate Lib "crypt32" ( _
ByVal hCryptProvOrNCryptKey As LongPtr, _
ByVal dwKeySpec As Long, _
ByVal dwCertEncodingType As Long, _
ByVal lpszStructType As String, _
ByVal pvStructInfo As LongPtr, _
ByVal pSignatureAlgorithm As LongPtr, _
ByVal pvHashAuxInfo As LongPtr, _
ByVal pbEncoded As LongPtr, _
ByRef pcbEncoded As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CryptSignAndEncodeCertificate = ctypes.windll.crypt32.CryptSignAndEncodeCertificate
CryptSignAndEncodeCertificate.restype = wintypes.BOOL
CryptSignAndEncodeCertificate.argtypes = [
ctypes.c_size_t, # hCryptProvOrNCryptKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
wintypes.DWORD, # dwKeySpec : CERT_KEY_SPEC optional
wintypes.DWORD, # dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
wintypes.LPCSTR, # lpszStructType : LPCSTR
ctypes.POINTER(None), # pvStructInfo : void*
ctypes.c_void_p, # pSignatureAlgorithm : CRYPT_ALGORITHM_IDENTIFIER*
ctypes.POINTER(None), # pvHashAuxInfo : void* optional
ctypes.POINTER(ctypes.c_ubyte), # pbEncoded : BYTE* optional, out
ctypes.POINTER(wintypes.DWORD), # pcbEncoded : DWORD* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('CRYPT32.dll')
CryptSignAndEncodeCertificate = Fiddle::Function.new(
lib['CryptSignAndEncodeCertificate'],
[
Fiddle::TYPE_UINTPTR_T, # hCryptProvOrNCryptKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
-Fiddle::TYPE_INT, # dwKeySpec : CERT_KEY_SPEC optional
-Fiddle::TYPE_INT, # dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
Fiddle::TYPE_VOIDP, # lpszStructType : LPCSTR
Fiddle::TYPE_VOIDP, # pvStructInfo : void*
Fiddle::TYPE_VOIDP, # pSignatureAlgorithm : CRYPT_ALGORITHM_IDENTIFIER*
Fiddle::TYPE_VOIDP, # pvHashAuxInfo : void* optional
Fiddle::TYPE_VOIDP, # pbEncoded : BYTE* optional, out
Fiddle::TYPE_VOIDP, # pcbEncoded : DWORD* in/out
],
Fiddle::TYPE_INT)#[link(name = "crypt32")]
extern "system" {
fn CryptSignAndEncodeCertificate(
hCryptProvOrNCryptKey: usize, // HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
dwKeySpec: u32, // CERT_KEY_SPEC optional
dwCertEncodingType: u32, // CERT_QUERY_ENCODING_TYPE
lpszStructType: *const u8, // LPCSTR
pvStructInfo: *const (), // void*
pSignatureAlgorithm: *mut CRYPT_ALGORITHM_IDENTIFIER, // CRYPT_ALGORITHM_IDENTIFIER*
pvHashAuxInfo: *const (), // void* optional
pbEncoded: *mut u8, // BYTE* optional, out
pcbEncoded: *mut u32 // DWORD* in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true)]
public static extern bool CryptSignAndEncodeCertificate(UIntPtr hCryptProvOrNCryptKey, uint dwKeySpec, uint dwCertEncodingType, [MarshalAs(UnmanagedType.LPStr)] string lpszStructType, IntPtr pvStructInfo, IntPtr pSignatureAlgorithm, IntPtr pvHashAuxInfo, IntPtr pbEncoded, ref uint pcbEncoded);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CryptSignAndEncodeCertificate' -Namespace Win32 -PassThru
# $api::CryptSignAndEncodeCertificate(hCryptProvOrNCryptKey, dwKeySpec, dwCertEncodingType, lpszStructType, pvStructInfo, pSignatureAlgorithm, pvHashAuxInfo, pbEncoded, pcbEncoded)#uselib "CRYPT32.dll"
#func global CryptSignAndEncodeCertificate "CryptSignAndEncodeCertificate" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; CryptSignAndEncodeCertificate hCryptProvOrNCryptKey, dwKeySpec, dwCertEncodingType, lpszStructType, pvStructInfo, varptr(pSignatureAlgorithm), pvHashAuxInfo, varptr(pbEncoded), varptr(pcbEncoded) ; 戻り値は stat
; hCryptProvOrNCryptKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> "sptr"
; dwKeySpec : CERT_KEY_SPEC optional -> "sptr"
; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "sptr"
; lpszStructType : LPCSTR -> "sptr"
; pvStructInfo : void* -> "sptr"
; pSignatureAlgorithm : CRYPT_ALGORITHM_IDENTIFIER* -> "sptr"
; pvHashAuxInfo : void* optional -> "sptr"
; pbEncoded : BYTE* optional, out -> "sptr"
; pcbEncoded : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "CRYPT32.dll" #cfunc global CryptSignAndEncodeCertificate "CryptSignAndEncodeCertificate" sptr, int, int, str, sptr, var, sptr, var, var ; res = CryptSignAndEncodeCertificate(hCryptProvOrNCryptKey, dwKeySpec, dwCertEncodingType, lpszStructType, pvStructInfo, pSignatureAlgorithm, pvHashAuxInfo, pbEncoded, pcbEncoded) ; hCryptProvOrNCryptKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> "sptr" ; dwKeySpec : CERT_KEY_SPEC optional -> "int" ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; lpszStructType : LPCSTR -> "str" ; pvStructInfo : void* -> "sptr" ; pSignatureAlgorithm : CRYPT_ALGORITHM_IDENTIFIER* -> "var" ; pvHashAuxInfo : void* optional -> "sptr" ; pbEncoded : BYTE* optional, out -> "var" ; pcbEncoded : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "CRYPT32.dll" #cfunc global CryptSignAndEncodeCertificate "CryptSignAndEncodeCertificate" sptr, int, int, str, sptr, sptr, sptr, sptr, sptr ; res = CryptSignAndEncodeCertificate(hCryptProvOrNCryptKey, dwKeySpec, dwCertEncodingType, lpszStructType, pvStructInfo, varptr(pSignatureAlgorithm), pvHashAuxInfo, varptr(pbEncoded), varptr(pcbEncoded)) ; hCryptProvOrNCryptKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> "sptr" ; dwKeySpec : CERT_KEY_SPEC optional -> "int" ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; lpszStructType : LPCSTR -> "str" ; pvStructInfo : void* -> "sptr" ; pSignatureAlgorithm : CRYPT_ALGORITHM_IDENTIFIER* -> "sptr" ; pvHashAuxInfo : void* optional -> "sptr" ; pbEncoded : BYTE* optional, out -> "sptr" ; pcbEncoded : DWORD* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; BOOL CryptSignAndEncodeCertificate(HCRYPTPROV_OR_NCRYPT_KEY_HANDLE hCryptProvOrNCryptKey, CERT_KEY_SPEC dwKeySpec, CERT_QUERY_ENCODING_TYPE dwCertEncodingType, LPCSTR lpszStructType, void* pvStructInfo, CRYPT_ALGORITHM_IDENTIFIER* pSignatureAlgorithm, void* pvHashAuxInfo, BYTE* pbEncoded, DWORD* pcbEncoded) #uselib "CRYPT32.dll" #cfunc global CryptSignAndEncodeCertificate "CryptSignAndEncodeCertificate" intptr, int, int, str, intptr, var, intptr, var, var ; res = CryptSignAndEncodeCertificate(hCryptProvOrNCryptKey, dwKeySpec, dwCertEncodingType, lpszStructType, pvStructInfo, pSignatureAlgorithm, pvHashAuxInfo, pbEncoded, pcbEncoded) ; hCryptProvOrNCryptKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> "intptr" ; dwKeySpec : CERT_KEY_SPEC optional -> "int" ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; lpszStructType : LPCSTR -> "str" ; pvStructInfo : void* -> "intptr" ; pSignatureAlgorithm : CRYPT_ALGORITHM_IDENTIFIER* -> "var" ; pvHashAuxInfo : void* optional -> "intptr" ; pbEncoded : BYTE* optional, out -> "var" ; pcbEncoded : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL CryptSignAndEncodeCertificate(HCRYPTPROV_OR_NCRYPT_KEY_HANDLE hCryptProvOrNCryptKey, CERT_KEY_SPEC dwKeySpec, CERT_QUERY_ENCODING_TYPE dwCertEncodingType, LPCSTR lpszStructType, void* pvStructInfo, CRYPT_ALGORITHM_IDENTIFIER* pSignatureAlgorithm, void* pvHashAuxInfo, BYTE* pbEncoded, DWORD* pcbEncoded) #uselib "CRYPT32.dll" #cfunc global CryptSignAndEncodeCertificate "CryptSignAndEncodeCertificate" intptr, int, int, str, intptr, intptr, intptr, intptr, intptr ; res = CryptSignAndEncodeCertificate(hCryptProvOrNCryptKey, dwKeySpec, dwCertEncodingType, lpszStructType, pvStructInfo, varptr(pSignatureAlgorithm), pvHashAuxInfo, varptr(pbEncoded), varptr(pcbEncoded)) ; hCryptProvOrNCryptKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> "intptr" ; dwKeySpec : CERT_KEY_SPEC optional -> "int" ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; lpszStructType : LPCSTR -> "str" ; pvStructInfo : void* -> "intptr" ; pSignatureAlgorithm : CRYPT_ALGORITHM_IDENTIFIER* -> "intptr" ; pvHashAuxInfo : void* optional -> "intptr" ; pbEncoded : BYTE* optional, out -> "intptr" ; pcbEncoded : DWORD* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
procCryptSignAndEncodeCertificate = crypt32.NewProc("CryptSignAndEncodeCertificate")
)
// hCryptProvOrNCryptKey (HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional), dwKeySpec (CERT_KEY_SPEC optional), dwCertEncodingType (CERT_QUERY_ENCODING_TYPE), lpszStructType (LPCSTR), pvStructInfo (void*), pSignatureAlgorithm (CRYPT_ALGORITHM_IDENTIFIER*), pvHashAuxInfo (void* optional), pbEncoded (BYTE* optional, out), pcbEncoded (DWORD* in/out)
r1, _, err := procCryptSignAndEncodeCertificate.Call(
uintptr(hCryptProvOrNCryptKey),
uintptr(dwKeySpec),
uintptr(dwCertEncodingType),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszStructType))),
uintptr(pvStructInfo),
uintptr(pSignatureAlgorithm),
uintptr(pvHashAuxInfo),
uintptr(pbEncoded),
uintptr(pcbEncoded),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CryptSignAndEncodeCertificate(
hCryptProvOrNCryptKey: NativeUInt; // HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
dwKeySpec: DWORD; // CERT_KEY_SPEC optional
dwCertEncodingType: DWORD; // CERT_QUERY_ENCODING_TYPE
lpszStructType: PAnsiChar; // LPCSTR
pvStructInfo: Pointer; // void*
pSignatureAlgorithm: Pointer; // CRYPT_ALGORITHM_IDENTIFIER*
pvHashAuxInfo: Pointer; // void* optional
pbEncoded: Pointer; // BYTE* optional, out
pcbEncoded: Pointer // DWORD* in/out
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CryptSignAndEncodeCertificate';result := DllCall("CRYPT32\CryptSignAndEncodeCertificate"
, "UPtr", hCryptProvOrNCryptKey ; HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
, "UInt", dwKeySpec ; CERT_KEY_SPEC optional
, "UInt", dwCertEncodingType ; CERT_QUERY_ENCODING_TYPE
, "AStr", lpszStructType ; LPCSTR
, "Ptr", pvStructInfo ; void*
, "Ptr", pSignatureAlgorithm ; CRYPT_ALGORITHM_IDENTIFIER*
, "Ptr", pvHashAuxInfo ; void* optional
, "Ptr", pbEncoded ; BYTE* optional, out
, "Ptr", pcbEncoded ; DWORD* in/out
, "Int") ; return: BOOL●CryptSignAndEncodeCertificate(hCryptProvOrNCryptKey, dwKeySpec, dwCertEncodingType, lpszStructType, pvStructInfo, pSignatureAlgorithm, pvHashAuxInfo, pbEncoded, pcbEncoded) = DLL("CRYPT32.dll", "bool CryptSignAndEncodeCertificate(int, dword, dword, char*, void*, void*, void*, void*, void*)")
# 呼び出し: CryptSignAndEncodeCertificate(hCryptProvOrNCryptKey, dwKeySpec, dwCertEncodingType, lpszStructType, pvStructInfo, pSignatureAlgorithm, pvHashAuxInfo, pbEncoded, pcbEncoded)
# hCryptProvOrNCryptKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> "int"
# dwKeySpec : CERT_KEY_SPEC optional -> "dword"
# dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "dword"
# lpszStructType : LPCSTR -> "char*"
# pvStructInfo : void* -> "void*"
# pSignatureAlgorithm : CRYPT_ALGORITHM_IDENTIFIER* -> "void*"
# pvHashAuxInfo : void* optional -> "void*"
# pbEncoded : BYTE* optional, out -> "void*"
# pcbEncoded : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "crypt32" fn CryptSignAndEncodeCertificate(
hCryptProvOrNCryptKey: usize, // HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
dwKeySpec: u32, // CERT_KEY_SPEC optional
dwCertEncodingType: u32, // CERT_QUERY_ENCODING_TYPE
lpszStructType: [*c]const u8, // LPCSTR
pvStructInfo: ?*anyopaque, // void*
pSignatureAlgorithm: [*c]CRYPT_ALGORITHM_IDENTIFIER, // CRYPT_ALGORITHM_IDENTIFIER*
pvHashAuxInfo: ?*anyopaque, // void* optional
pbEncoded: [*c]u8, // BYTE* optional, out
pcbEncoded: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) i32;proc CryptSignAndEncodeCertificate(
hCryptProvOrNCryptKey: uint, # HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
dwKeySpec: uint32, # CERT_KEY_SPEC optional
dwCertEncodingType: uint32, # CERT_QUERY_ENCODING_TYPE
lpszStructType: cstring, # LPCSTR
pvStructInfo: pointer, # void*
pSignatureAlgorithm: ptr CRYPT_ALGORITHM_IDENTIFIER, # CRYPT_ALGORITHM_IDENTIFIER*
pvHashAuxInfo: pointer, # void* optional
pbEncoded: ptr uint8, # BYTE* optional, out
pcbEncoded: ptr uint32 # DWORD* in/out
): int32 {.importc: "CryptSignAndEncodeCertificate", stdcall, dynlib: "CRYPT32.dll".}pragma(lib, "crypt32");
extern(Windows)
int CryptSignAndEncodeCertificate(
size_t hCryptProvOrNCryptKey, // HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
uint dwKeySpec, // CERT_KEY_SPEC optional
uint dwCertEncodingType, // CERT_QUERY_ENCODING_TYPE
const(char)* lpszStructType, // LPCSTR
void* pvStructInfo, // void*
CRYPT_ALGORITHM_IDENTIFIER* pSignatureAlgorithm, // CRYPT_ALGORITHM_IDENTIFIER*
void* pvHashAuxInfo, // void* optional
ubyte* pbEncoded, // BYTE* optional, out
uint* pcbEncoded // DWORD* in/out
);ccall((:CryptSignAndEncodeCertificate, "CRYPT32.dll"), stdcall, Int32,
(Csize_t, UInt32, UInt32, Cstring, Ptr{Cvoid}, Ptr{CRYPT_ALGORITHM_IDENTIFIER}, Ptr{Cvoid}, Ptr{UInt8}, Ptr{UInt32}),
hCryptProvOrNCryptKey, dwKeySpec, dwCertEncodingType, lpszStructType, pvStructInfo, pSignatureAlgorithm, pvHashAuxInfo, pbEncoded, pcbEncoded)
# hCryptProvOrNCryptKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> Csize_t
# dwKeySpec : CERT_KEY_SPEC optional -> UInt32
# dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> UInt32
# lpszStructType : LPCSTR -> Cstring
# pvStructInfo : void* -> Ptr{Cvoid}
# pSignatureAlgorithm : CRYPT_ALGORITHM_IDENTIFIER* -> Ptr{CRYPT_ALGORITHM_IDENTIFIER}
# pvHashAuxInfo : void* optional -> Ptr{Cvoid}
# pbEncoded : BYTE* optional, out -> Ptr{UInt8}
# pcbEncoded : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t CryptSignAndEncodeCertificate(
uintptr_t hCryptProvOrNCryptKey,
uint32_t dwKeySpec,
uint32_t dwCertEncodingType,
const char* lpszStructType,
void* pvStructInfo,
void* pSignatureAlgorithm,
void* pvHashAuxInfo,
uint8_t* pbEncoded,
uint32_t* pcbEncoded);
]]
local crypt32 = ffi.load("crypt32")
-- crypt32.CryptSignAndEncodeCertificate(hCryptProvOrNCryptKey, dwKeySpec, dwCertEncodingType, lpszStructType, pvStructInfo, pSignatureAlgorithm, pvHashAuxInfo, pbEncoded, pcbEncoded)
-- hCryptProvOrNCryptKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
-- dwKeySpec : CERT_KEY_SPEC optional
-- dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
-- lpszStructType : LPCSTR
-- pvStructInfo : void*
-- pSignatureAlgorithm : CRYPT_ALGORITHM_IDENTIFIER*
-- pvHashAuxInfo : void* optional
-- pbEncoded : BYTE* optional, out
-- pcbEncoded : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('CRYPT32.dll');
const CryptSignAndEncodeCertificate = lib.func('__stdcall', 'CryptSignAndEncodeCertificate', 'int32_t', ['uintptr_t', 'uint32_t', 'uint32_t', 'str', 'void *', 'void *', 'void *', 'uint8_t *', 'uint32_t *']);
// CryptSignAndEncodeCertificate(hCryptProvOrNCryptKey, dwKeySpec, dwCertEncodingType, lpszStructType, pvStructInfo, pSignatureAlgorithm, pvHashAuxInfo, pbEncoded, pcbEncoded)
// hCryptProvOrNCryptKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> 'uintptr_t'
// dwKeySpec : CERT_KEY_SPEC optional -> 'uint32_t'
// dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> 'uint32_t'
// lpszStructType : LPCSTR -> 'str'
// pvStructInfo : void* -> 'void *'
// pSignatureAlgorithm : CRYPT_ALGORITHM_IDENTIFIER* -> 'void *'
// pvHashAuxInfo : void* optional -> 'void *'
// pbEncoded : BYTE* optional, out -> 'uint8_t *'
// pcbEncoded : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("CRYPT32.dll", {
CryptSignAndEncodeCertificate: { parameters: ["usize", "u32", "u32", "buffer", "pointer", "pointer", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.CryptSignAndEncodeCertificate(hCryptProvOrNCryptKey, dwKeySpec, dwCertEncodingType, lpszStructType, pvStructInfo, pSignatureAlgorithm, pvHashAuxInfo, pbEncoded, pcbEncoded)
// hCryptProvOrNCryptKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> "usize"
// dwKeySpec : CERT_KEY_SPEC optional -> "u32"
// dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "u32"
// lpszStructType : LPCSTR -> "buffer"
// pvStructInfo : void* -> "pointer"
// pSignatureAlgorithm : CRYPT_ALGORITHM_IDENTIFIER* -> "pointer"
// pvHashAuxInfo : void* optional -> "pointer"
// pbEncoded : BYTE* optional, out -> "pointer"
// pcbEncoded : DWORD* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CryptSignAndEncodeCertificate(
size_t hCryptProvOrNCryptKey,
uint32_t dwKeySpec,
uint32_t dwCertEncodingType,
const char* lpszStructType,
void* pvStructInfo,
void* pSignatureAlgorithm,
void* pvHashAuxInfo,
uint8_t* pbEncoded,
uint32_t* pcbEncoded);
C, "CRYPT32.dll");
// $ffi->CryptSignAndEncodeCertificate(hCryptProvOrNCryptKey, dwKeySpec, dwCertEncodingType, lpszStructType, pvStructInfo, pSignatureAlgorithm, pvHashAuxInfo, pbEncoded, pcbEncoded);
// hCryptProvOrNCryptKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
// dwKeySpec : CERT_KEY_SPEC optional
// dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
// lpszStructType : LPCSTR
// pvStructInfo : void*
// pSignatureAlgorithm : CRYPT_ALGORITHM_IDENTIFIER*
// pvHashAuxInfo : void* optional
// pbEncoded : BYTE* optional, out
// pcbEncoded : DWORD* in/out
// 構造体/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 Crypt32 extends StdCallLibrary {
Crypt32 INSTANCE = Native.load("crypt32", Crypt32.class);
boolean CryptSignAndEncodeCertificate(
long hCryptProvOrNCryptKey, // HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
int dwKeySpec, // CERT_KEY_SPEC optional
int dwCertEncodingType, // CERT_QUERY_ENCODING_TYPE
String lpszStructType, // LPCSTR
Pointer pvStructInfo, // void*
Pointer pSignatureAlgorithm, // CRYPT_ALGORITHM_IDENTIFIER*
Pointer pvHashAuxInfo, // void* optional
byte[] pbEncoded, // BYTE* optional, out
IntByReference pcbEncoded // DWORD* in/out
);
}@[Link("crypt32")]
lib LibCRYPT32
fun CryptSignAndEncodeCertificate = CryptSignAndEncodeCertificate(
hCryptProvOrNCryptKey : LibC::SizeT, # HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
dwKeySpec : UInt32, # CERT_KEY_SPEC optional
dwCertEncodingType : UInt32, # CERT_QUERY_ENCODING_TYPE
lpszStructType : UInt8*, # LPCSTR
pvStructInfo : Void*, # void*
pSignatureAlgorithm : CRYPT_ALGORITHM_IDENTIFIER*, # CRYPT_ALGORITHM_IDENTIFIER*
pvHashAuxInfo : Void*, # void* optional
pbEncoded : UInt8*, # BYTE* optional, out
pcbEncoded : UInt32* # DWORD* in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CryptSignAndEncodeCertificateNative = Int32 Function(UintPtr, Uint32, Uint32, Pointer<Utf8>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Uint8>, Pointer<Uint32>);
typedef CryptSignAndEncodeCertificateDart = int Function(int, int, int, Pointer<Utf8>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Uint8>, Pointer<Uint32>);
final CryptSignAndEncodeCertificate = DynamicLibrary.open('CRYPT32.dll')
.lookupFunction<CryptSignAndEncodeCertificateNative, CryptSignAndEncodeCertificateDart>('CryptSignAndEncodeCertificate');
// hCryptProvOrNCryptKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> UintPtr
// dwKeySpec : CERT_KEY_SPEC optional -> Uint32
// dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> Uint32
// lpszStructType : LPCSTR -> Pointer<Utf8>
// pvStructInfo : void* -> Pointer<Void>
// pSignatureAlgorithm : CRYPT_ALGORITHM_IDENTIFIER* -> Pointer<Void>
// pvHashAuxInfo : void* optional -> Pointer<Void>
// pbEncoded : BYTE* optional, out -> Pointer<Uint8>
// pcbEncoded : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CryptSignAndEncodeCertificate(
hCryptProvOrNCryptKey: NativeUInt; // HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
dwKeySpec: DWORD; // CERT_KEY_SPEC optional
dwCertEncodingType: DWORD; // CERT_QUERY_ENCODING_TYPE
lpszStructType: PAnsiChar; // LPCSTR
pvStructInfo: Pointer; // void*
pSignatureAlgorithm: Pointer; // CRYPT_ALGORITHM_IDENTIFIER*
pvHashAuxInfo: Pointer; // void* optional
pbEncoded: Pointer; // BYTE* optional, out
pcbEncoded: Pointer // DWORD* in/out
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CryptSignAndEncodeCertificate';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CryptSignAndEncodeCertificate"
c_CryptSignAndEncodeCertificate :: CUIntPtr -> Word32 -> Word32 -> CString -> Ptr () -> Ptr () -> Ptr () -> Ptr Word8 -> Ptr Word32 -> IO CInt
-- hCryptProvOrNCryptKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> CUIntPtr
-- dwKeySpec : CERT_KEY_SPEC optional -> Word32
-- dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> Word32
-- lpszStructType : LPCSTR -> CString
-- pvStructInfo : void* -> Ptr ()
-- pSignatureAlgorithm : CRYPT_ALGORITHM_IDENTIFIER* -> Ptr ()
-- pvHashAuxInfo : void* optional -> Ptr ()
-- pbEncoded : BYTE* optional, out -> Ptr Word8
-- pcbEncoded : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let cryptsignandencodecertificate =
foreign "CryptSignAndEncodeCertificate"
(size_t @-> uint32_t @-> uint32_t @-> string @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr uint8_t) @-> (ptr uint32_t) @-> returning int32_t)
(* hCryptProvOrNCryptKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> size_t *)
(* dwKeySpec : CERT_KEY_SPEC optional -> uint32_t *)
(* dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> uint32_t *)
(* lpszStructType : LPCSTR -> string *)
(* pvStructInfo : void* -> (ptr void) *)
(* pSignatureAlgorithm : CRYPT_ALGORITHM_IDENTIFIER* -> (ptr void) *)
(* pvHashAuxInfo : void* optional -> (ptr void) *)
(* pbEncoded : BYTE* optional, out -> (ptr uint8_t) *)
(* pcbEncoded : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library crypt32 (t "CRYPT32.dll"))
(cffi:use-foreign-library crypt32)
(cffi:defcfun ("CryptSignAndEncodeCertificate" crypt-sign-and-encode-certificate :convention :stdcall) :int32
(h-crypt-prov-or-ncrypt-key :uint64) ; HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional
(dw-key-spec :uint32) ; CERT_KEY_SPEC optional
(dw-cert-encoding-type :uint32) ; CERT_QUERY_ENCODING_TYPE
(lpsz-struct-type :string) ; LPCSTR
(pv-struct-info :pointer) ; void*
(p-signature-algorithm :pointer) ; CRYPT_ALGORITHM_IDENTIFIER*
(pv-hash-aux-info :pointer) ; void* optional
(pb-encoded :pointer) ; BYTE* optional, out
(pcb-encoded :pointer)) ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CryptSignAndEncodeCertificate = Win32::API::More->new('CRYPT32',
'BOOL CryptSignAndEncodeCertificate(WPARAM hCryptProvOrNCryptKey, DWORD dwKeySpec, DWORD dwCertEncodingType, LPCSTR lpszStructType, LPVOID pvStructInfo, LPVOID pSignatureAlgorithm, LPVOID pvHashAuxInfo, LPVOID pbEncoded, LPVOID pcbEncoded)');
# my $ret = $CryptSignAndEncodeCertificate->Call($hCryptProvOrNCryptKey, $dwKeySpec, $dwCertEncodingType, $lpszStructType, $pvStructInfo, $pSignatureAlgorithm, $pvHashAuxInfo, $pbEncoded, $pcbEncoded);
# hCryptProvOrNCryptKey : HCRYPTPROV_OR_NCRYPT_KEY_HANDLE optional -> WPARAM
# dwKeySpec : CERT_KEY_SPEC optional -> DWORD
# dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> DWORD
# lpszStructType : LPCSTR -> LPCSTR
# pvStructInfo : void* -> LPVOID
# pSignatureAlgorithm : CRYPT_ALGORITHM_IDENTIFIER* -> LPVOID
# pvHashAuxInfo : void* optional -> LPVOID
# pbEncoded : BYTE* optional, out -> LPVOID
# pcbEncoded : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f CryptSignCertificate — 被署名データに署名して証明書署名値を生成する。