ホーム › Security.Cryptography › CryptFormatObject
CryptFormatObject
関数エンコード済みデータを表示用文字列に整形する。
シグネチャ
// CRYPT32.dll
#include <windows.h>
BOOL CryptFormatObject(
CERT_QUERY_ENCODING_TYPE dwCertEncodingType,
DWORD dwFormatType,
DWORD dwFormatStrType,
void* pFormatStruct, // optional
LPCSTR lpszStructType, // optional
const BYTE* pbEncoded,
DWORD cbEncoded,
void* pbFormat, // optional
DWORD* pcbFormat
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| dwCertEncodingType | CERT_QUERY_ENCODING_TYPE | in |
| dwFormatType | DWORD | in |
| dwFormatStrType | DWORD | in |
| pFormatStruct | void* | inoptional |
| lpszStructType | LPCSTR | inoptional |
| pbEncoded | BYTE* | in |
| cbEncoded | DWORD | in |
| pbFormat | void* | outoptional |
| pcbFormat | DWORD* | inout |
戻り値の型: BOOL
各言語での呼び出し定義
// CRYPT32.dll
#include <windows.h>
BOOL CryptFormatObject(
CERT_QUERY_ENCODING_TYPE dwCertEncodingType,
DWORD dwFormatType,
DWORD dwFormatStrType,
void* pFormatStruct, // optional
LPCSTR lpszStructType, // optional
const BYTE* pbEncoded,
DWORD cbEncoded,
void* pbFormat, // optional
DWORD* pcbFormat
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CryptFormatObject(
uint dwCertEncodingType, // CERT_QUERY_ENCODING_TYPE
uint dwFormatType, // DWORD
uint dwFormatStrType, // DWORD
IntPtr pFormatStruct, // void* optional
[MarshalAs(UnmanagedType.LPStr)] string lpszStructType, // LPCSTR optional
IntPtr pbEncoded, // BYTE*
uint cbEncoded, // DWORD
IntPtr pbFormat, // void* optional, out
ref uint pcbFormat // DWORD* in/out
);<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CryptFormatObject(
dwCertEncodingType As UInteger, ' CERT_QUERY_ENCODING_TYPE
dwFormatType As UInteger, ' DWORD
dwFormatStrType As UInteger, ' DWORD
pFormatStruct As IntPtr, ' void* optional
<MarshalAs(UnmanagedType.LPStr)> lpszStructType As String, ' LPCSTR optional
pbEncoded As IntPtr, ' BYTE*
cbEncoded As UInteger, ' DWORD
pbFormat As IntPtr, ' void* optional, out
ByRef pcbFormat As UInteger ' DWORD* in/out
) As Boolean
End Function' dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
' dwFormatType : DWORD
' dwFormatStrType : DWORD
' pFormatStruct : void* optional
' lpszStructType : LPCSTR optional
' pbEncoded : BYTE*
' cbEncoded : DWORD
' pbFormat : void* optional, out
' pcbFormat : DWORD* in/out
Declare PtrSafe Function CryptFormatObject Lib "crypt32" ( _
ByVal dwCertEncodingType As Long, _
ByVal dwFormatType As Long, _
ByVal dwFormatStrType As Long, _
ByVal pFormatStruct As LongPtr, _
ByVal lpszStructType As String, _
ByVal pbEncoded As LongPtr, _
ByVal cbEncoded As Long, _
ByVal pbFormat As LongPtr, _
ByRef pcbFormat As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CryptFormatObject = ctypes.windll.crypt32.CryptFormatObject
CryptFormatObject.restype = wintypes.BOOL
CryptFormatObject.argtypes = [
wintypes.DWORD, # dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
wintypes.DWORD, # dwFormatType : DWORD
wintypes.DWORD, # dwFormatStrType : DWORD
ctypes.POINTER(None), # pFormatStruct : void* optional
wintypes.LPCSTR, # lpszStructType : LPCSTR optional
ctypes.POINTER(ctypes.c_ubyte), # pbEncoded : BYTE*
wintypes.DWORD, # cbEncoded : DWORD
ctypes.POINTER(None), # pbFormat : void* optional, out
ctypes.POINTER(wintypes.DWORD), # pcbFormat : DWORD* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('CRYPT32.dll')
CryptFormatObject = Fiddle::Function.new(
lib['CryptFormatObject'],
[
-Fiddle::TYPE_INT, # dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
-Fiddle::TYPE_INT, # dwFormatType : DWORD
-Fiddle::TYPE_INT, # dwFormatStrType : DWORD
Fiddle::TYPE_VOIDP, # pFormatStruct : void* optional
Fiddle::TYPE_VOIDP, # lpszStructType : LPCSTR optional
Fiddle::TYPE_VOIDP, # pbEncoded : BYTE*
-Fiddle::TYPE_INT, # cbEncoded : DWORD
Fiddle::TYPE_VOIDP, # pbFormat : void* optional, out
Fiddle::TYPE_VOIDP, # pcbFormat : DWORD* in/out
],
Fiddle::TYPE_INT)#[link(name = "crypt32")]
extern "system" {
fn CryptFormatObject(
dwCertEncodingType: u32, // CERT_QUERY_ENCODING_TYPE
dwFormatType: u32, // DWORD
dwFormatStrType: u32, // DWORD
pFormatStruct: *mut (), // void* optional
lpszStructType: *const u8, // LPCSTR optional
pbEncoded: *const u8, // BYTE*
cbEncoded: u32, // DWORD
pbFormat: *mut (), // void* optional, out
pcbFormat: *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 CryptFormatObject(uint dwCertEncodingType, uint dwFormatType, uint dwFormatStrType, IntPtr pFormatStruct, [MarshalAs(UnmanagedType.LPStr)] string lpszStructType, IntPtr pbEncoded, uint cbEncoded, IntPtr pbFormat, ref uint pcbFormat);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CryptFormatObject' -Namespace Win32 -PassThru
# $api::CryptFormatObject(dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct, lpszStructType, pbEncoded, cbEncoded, pbFormat, pcbFormat)#uselib "CRYPT32.dll"
#func global CryptFormatObject "CryptFormatObject" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; CryptFormatObject dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct, lpszStructType, varptr(pbEncoded), cbEncoded, pbFormat, varptr(pcbFormat) ; 戻り値は stat
; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "sptr"
; dwFormatType : DWORD -> "sptr"
; dwFormatStrType : DWORD -> "sptr"
; pFormatStruct : void* optional -> "sptr"
; lpszStructType : LPCSTR optional -> "sptr"
; pbEncoded : BYTE* -> "sptr"
; cbEncoded : DWORD -> "sptr"
; pbFormat : void* optional, out -> "sptr"
; pcbFormat : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "CRYPT32.dll" #cfunc global CryptFormatObject "CryptFormatObject" int, int, int, sptr, str, var, int, sptr, var ; res = CryptFormatObject(dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct, lpszStructType, pbEncoded, cbEncoded, pbFormat, pcbFormat) ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; dwFormatType : DWORD -> "int" ; dwFormatStrType : DWORD -> "int" ; pFormatStruct : void* optional -> "sptr" ; lpszStructType : LPCSTR optional -> "str" ; pbEncoded : BYTE* -> "var" ; cbEncoded : DWORD -> "int" ; pbFormat : void* optional, out -> "sptr" ; pcbFormat : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "CRYPT32.dll" #cfunc global CryptFormatObject "CryptFormatObject" int, int, int, sptr, str, sptr, int, sptr, sptr ; res = CryptFormatObject(dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct, lpszStructType, varptr(pbEncoded), cbEncoded, pbFormat, varptr(pcbFormat)) ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; dwFormatType : DWORD -> "int" ; dwFormatStrType : DWORD -> "int" ; pFormatStruct : void* optional -> "sptr" ; lpszStructType : LPCSTR optional -> "str" ; pbEncoded : BYTE* -> "sptr" ; cbEncoded : DWORD -> "int" ; pbFormat : void* optional, out -> "sptr" ; pcbFormat : DWORD* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL CryptFormatObject(CERT_QUERY_ENCODING_TYPE dwCertEncodingType, DWORD dwFormatType, DWORD dwFormatStrType, void* pFormatStruct, LPCSTR lpszStructType, BYTE* pbEncoded, DWORD cbEncoded, void* pbFormat, DWORD* pcbFormat) #uselib "CRYPT32.dll" #cfunc global CryptFormatObject "CryptFormatObject" int, int, int, intptr, str, var, int, intptr, var ; res = CryptFormatObject(dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct, lpszStructType, pbEncoded, cbEncoded, pbFormat, pcbFormat) ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; dwFormatType : DWORD -> "int" ; dwFormatStrType : DWORD -> "int" ; pFormatStruct : void* optional -> "intptr" ; lpszStructType : LPCSTR optional -> "str" ; pbEncoded : BYTE* -> "var" ; cbEncoded : DWORD -> "int" ; pbFormat : void* optional, out -> "intptr" ; pcbFormat : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL CryptFormatObject(CERT_QUERY_ENCODING_TYPE dwCertEncodingType, DWORD dwFormatType, DWORD dwFormatStrType, void* pFormatStruct, LPCSTR lpszStructType, BYTE* pbEncoded, DWORD cbEncoded, void* pbFormat, DWORD* pcbFormat) #uselib "CRYPT32.dll" #cfunc global CryptFormatObject "CryptFormatObject" int, int, int, intptr, str, intptr, int, intptr, intptr ; res = CryptFormatObject(dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct, lpszStructType, varptr(pbEncoded), cbEncoded, pbFormat, varptr(pcbFormat)) ; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int" ; dwFormatType : DWORD -> "int" ; dwFormatStrType : DWORD -> "int" ; pFormatStruct : void* optional -> "intptr" ; lpszStructType : LPCSTR optional -> "str" ; pbEncoded : BYTE* -> "intptr" ; cbEncoded : DWORD -> "int" ; pbFormat : void* optional, out -> "intptr" ; pcbFormat : DWORD* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
procCryptFormatObject = crypt32.NewProc("CryptFormatObject")
)
// dwCertEncodingType (CERT_QUERY_ENCODING_TYPE), dwFormatType (DWORD), dwFormatStrType (DWORD), pFormatStruct (void* optional), lpszStructType (LPCSTR optional), pbEncoded (BYTE*), cbEncoded (DWORD), pbFormat (void* optional, out), pcbFormat (DWORD* in/out)
r1, _, err := procCryptFormatObject.Call(
uintptr(dwCertEncodingType),
uintptr(dwFormatType),
uintptr(dwFormatStrType),
uintptr(pFormatStruct),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszStructType))),
uintptr(pbEncoded),
uintptr(cbEncoded),
uintptr(pbFormat),
uintptr(pcbFormat),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CryptFormatObject(
dwCertEncodingType: DWORD; // CERT_QUERY_ENCODING_TYPE
dwFormatType: DWORD; // DWORD
dwFormatStrType: DWORD; // DWORD
pFormatStruct: Pointer; // void* optional
lpszStructType: PAnsiChar; // LPCSTR optional
pbEncoded: Pointer; // BYTE*
cbEncoded: DWORD; // DWORD
pbFormat: Pointer; // void* optional, out
pcbFormat: Pointer // DWORD* in/out
): BOOL; stdcall;
external 'CRYPT32.dll' name 'CryptFormatObject';result := DllCall("CRYPT32\CryptFormatObject"
, "UInt", dwCertEncodingType ; CERT_QUERY_ENCODING_TYPE
, "UInt", dwFormatType ; DWORD
, "UInt", dwFormatStrType ; DWORD
, "Ptr", pFormatStruct ; void* optional
, "AStr", lpszStructType ; LPCSTR optional
, "Ptr", pbEncoded ; BYTE*
, "UInt", cbEncoded ; DWORD
, "Ptr", pbFormat ; void* optional, out
, "Ptr", pcbFormat ; DWORD* in/out
, "Int") ; return: BOOL●CryptFormatObject(dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct, lpszStructType, pbEncoded, cbEncoded, pbFormat, pcbFormat) = DLL("CRYPT32.dll", "bool CryptFormatObject(dword, dword, dword, void*, char*, void*, dword, void*, void*)")
# 呼び出し: CryptFormatObject(dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct, lpszStructType, pbEncoded, cbEncoded, pbFormat, pcbFormat)
# dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "dword"
# dwFormatType : DWORD -> "dword"
# dwFormatStrType : DWORD -> "dword"
# pFormatStruct : void* optional -> "void*"
# lpszStructType : LPCSTR optional -> "char*"
# pbEncoded : BYTE* -> "void*"
# cbEncoded : DWORD -> "dword"
# pbFormat : void* optional, out -> "void*"
# pcbFormat : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。