ホーム › Security.Cryptography › CertGetPublicKeyLength
CertGetPublicKeyLength
関数公開鍵情報からビット単位の鍵長を取得する。
シグネチャ
// CRYPT32.dll
#include <windows.h>
DWORD CertGetPublicKeyLength(
CERT_QUERY_ENCODING_TYPE dwCertEncodingType,
CERT_PUBLIC_KEY_INFO* pPublicKey
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| dwCertEncodingType | CERT_QUERY_ENCODING_TYPE | in |
| pPublicKey | CERT_PUBLIC_KEY_INFO* | in |
戻り値の型: DWORD
各言語での呼び出し定義
// CRYPT32.dll
#include <windows.h>
DWORD CertGetPublicKeyLength(
CERT_QUERY_ENCODING_TYPE dwCertEncodingType,
CERT_PUBLIC_KEY_INFO* pPublicKey
);[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern uint CertGetPublicKeyLength(
uint dwCertEncodingType, // CERT_QUERY_ENCODING_TYPE
IntPtr pPublicKey // CERT_PUBLIC_KEY_INFO*
);<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CertGetPublicKeyLength(
dwCertEncodingType As UInteger, ' CERT_QUERY_ENCODING_TYPE
pPublicKey As IntPtr ' CERT_PUBLIC_KEY_INFO*
) As UInteger
End Function' dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
' pPublicKey : CERT_PUBLIC_KEY_INFO*
Declare PtrSafe Function CertGetPublicKeyLength Lib "crypt32" ( _
ByVal dwCertEncodingType As Long, _
ByVal pPublicKey As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CertGetPublicKeyLength = ctypes.windll.crypt32.CertGetPublicKeyLength
CertGetPublicKeyLength.restype = wintypes.DWORD
CertGetPublicKeyLength.argtypes = [
wintypes.DWORD, # dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
ctypes.c_void_p, # pPublicKey : CERT_PUBLIC_KEY_INFO*
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('CRYPT32.dll')
CertGetPublicKeyLength = Fiddle::Function.new(
lib['CertGetPublicKeyLength'],
[
-Fiddle::TYPE_INT, # dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
Fiddle::TYPE_VOIDP, # pPublicKey : CERT_PUBLIC_KEY_INFO*
],
-Fiddle::TYPE_INT)#[link(name = "crypt32")]
extern "system" {
fn CertGetPublicKeyLength(
dwCertEncodingType: u32, // CERT_QUERY_ENCODING_TYPE
pPublicKey: *mut CERT_PUBLIC_KEY_INFO // CERT_PUBLIC_KEY_INFO*
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("CRYPT32.dll", SetLastError = true)]
public static extern uint CertGetPublicKeyLength(uint dwCertEncodingType, IntPtr pPublicKey);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CertGetPublicKeyLength' -Namespace Win32 -PassThru
# $api::CertGetPublicKeyLength(dwCertEncodingType, pPublicKey)#uselib "CRYPT32.dll"
#func global CertGetPublicKeyLength "CertGetPublicKeyLength" sptr, sptr
; CertGetPublicKeyLength dwCertEncodingType, varptr(pPublicKey) ; 戻り値は stat
; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "sptr"
; pPublicKey : CERT_PUBLIC_KEY_INFO* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "CRYPT32.dll" #cfunc global CertGetPublicKeyLength "CertGetPublicKeyLength" int, var ; res = CertGetPublicKeyLength(dwCertEncodingType, pPublicKey) ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; pPublicKey : CERT_PUBLIC_KEY_INFO* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "CRYPT32.dll" #cfunc global CertGetPublicKeyLength "CertGetPublicKeyLength" int, sptr ; res = CertGetPublicKeyLength(dwCertEncodingType, varptr(pPublicKey)) ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; pPublicKey : CERT_PUBLIC_KEY_INFO* -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD CertGetPublicKeyLength(CERT_QUERY_ENCODING_TYPE dwCertEncodingType, CERT_PUBLIC_KEY_INFO* pPublicKey) #uselib "CRYPT32.dll" #cfunc global CertGetPublicKeyLength "CertGetPublicKeyLength" int, var ; res = CertGetPublicKeyLength(dwCertEncodingType, pPublicKey) ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; pPublicKey : CERT_PUBLIC_KEY_INFO* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD CertGetPublicKeyLength(CERT_QUERY_ENCODING_TYPE dwCertEncodingType, CERT_PUBLIC_KEY_INFO* pPublicKey) #uselib "CRYPT32.dll" #cfunc global CertGetPublicKeyLength "CertGetPublicKeyLength" int, intptr ; res = CertGetPublicKeyLength(dwCertEncodingType, varptr(pPublicKey)) ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; pPublicKey : CERT_PUBLIC_KEY_INFO* -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
procCertGetPublicKeyLength = crypt32.NewProc("CertGetPublicKeyLength")
)
// dwCertEncodingType (CERT_QUERY_ENCODING_TYPE), pPublicKey (CERT_PUBLIC_KEY_INFO*)
r1, _, err := procCertGetPublicKeyLength.Call(
uintptr(dwCertEncodingType),
uintptr(pPublicKey),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction CertGetPublicKeyLength(
dwCertEncodingType: DWORD; // CERT_QUERY_ENCODING_TYPE
pPublicKey: Pointer // CERT_PUBLIC_KEY_INFO*
): DWORD; stdcall;
external 'CRYPT32.dll' name 'CertGetPublicKeyLength';result := DllCall("CRYPT32\CertGetPublicKeyLength"
, "UInt", dwCertEncodingType ; CERT_QUERY_ENCODING_TYPE
, "Ptr", pPublicKey ; CERT_PUBLIC_KEY_INFO*
, "UInt") ; return: DWORD●CertGetPublicKeyLength(dwCertEncodingType, pPublicKey) = DLL("CRYPT32.dll", "dword CertGetPublicKeyLength(dword, void*)")
# 呼び出し: CertGetPublicKeyLength(dwCertEncodingType, pPublicKey)
# dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "dword"
# pPublicKey : CERT_PUBLIC_KEY_INFO* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。