CryptoSys PKI Pro Manual

ASN1_Type

Describes the type of ASN.1 data.

VBA/VB6 Syntax

Public Declare Function ASN1_Type Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strFileOrPEMString As String, ByVal nOptions As Long) As Long

nRet = ASN1_Type(strOutput, nOutChars, strFileOrPEMString, nOptions)

C/C++ Syntax

long __stdcall ASN1_Type(char *szOutput, long nOutChars, const char *szFileOrPEMString, long nOptions);

Parameters

szOutput
[out] string of sufficient length to receive the output (guaranteed not to be longer than PKI_ASN1_TYPE_MAXCHARS).
nOutChars
[in] specifying the maximum number of characters to be received.
szFileOrPEMString
[in] filename of ASN.1 formatted data file to be analyzed (or its base64 representation or PEM string).
nOptions
[in] option flags: not used in this release. Specify zero.

Returns (VBA/C)

If successful, the return value is the number of characters in or required for the output string; otherwise it returns a negative error code.

VBA Wrapper Syntax

Public Function asn1Type (szFileOrPEMString As String, Optional nOptions As Long = 0) As String

.NET Equivalent

Asn1.Type Method

C++ (STL) Equivalent

static std::string dipki::Asn1::Type (const std::string &asn1File)

Python Equivalent

static Asn1.type(asn1file)

Remarks

For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length. Specify a zero nOutChars or an empty string for szOutput to find the required length. ANSI C users must add one to this value when allocating memory.

The input may be a binary file in BER/DER format or a text file in PEM or base64 format, or may be passed as a base64 string or as a PEM string. The output is a string describing the most likely type of the ASN.1-formatted data, or an empty string ("") if the type cannot be determined. The following types are detected:

Output string valueASN.1 object typeReference
EC PRIVATE KEY ECPrivateKey [RFC5915]
OCSP REQUEST OCSPRequest [RFC6960]
OCSP RESPONSE OCSPResponse [RFC6960]
PKCS1 RSA PRIVATE KEY RSAPrivateKey [RFC3447]
PKCS1 RSA PUBLIC KEY RSAPublicKey [RFC3447]
PKCS10 CERTIFICATE REQUEST CertificationRequest [RFC2986]
PKCS12 PFX PFX [RFC7292]
PKCS7 CERTIFICATE CHAIN ContentInfo [RFC5652]
PKCS7/CMS COMPRESSED DATA ContentInfo [RFC3274]
PKCS7/CMS DATA ContentInfo [RFC5652]
PKCS7/CMS ENVELOPED DATA ContentInfo [RFC5652]
CMS AUTH ENVELOPED DATA ContentInfo [RFC5083]
PKCS7/CMS SIGNED DATA ContentInfo [RFC5652]
PKCS8 ENCRYPTED PRIVATE KEYEncryptedPrivateKeyInfo[RFC5208], [RFC5958]
PKCS8 PRIVATE KEY INFOPrivateKeyInfo[RFC5208], [RFC5958]
PKCS8 ONE ASYMMETRIC KEYOneAsymmetricKey[RFC5958]
PUBLIC KEY INFOSubjectPublicKeyInfo[RFC3279], [RFC5480]
X509 CERTIFICATECertificate[RFC5280]
X509 CRLCertificateList[RFC5280]

Note that these descriptions are not necessarily those used as labels for PEM formatted files. See PEM_FileFromBinFile and [RFC7468].

Example (VBA core function)

Dim nChars As Long
Dim strTypeName As String

' Output guaranteed not to be longer than PKI_ASN1_TYPE_MAXCHARS characters
strTypeName = String(PKI_ASN1_TYPE_MAXCHARS, " ")
nChars = ASN1_Type(strTypeName, Len(strTypeName), "AliceRSASignByCarl.cer", 0)
If nChars > 0 Then Debug.Print Left(strTypeName, nChars)

strTypeName = String(PKI_ASN1_TYPE_MAXCHARS, " ")
nChars = ASN1_Type(strTypeName, Len(strTypeName), "AlicePrivRSASign.pri", 0)
If nChars > 0 Then Debug.Print Left(strTypeName, nChars)

strTypeName = String(PKI_ASN1_TYPE_MAXCHARS, " ")
nChars = ASN1_Type(strTypeName, Len(strTypeName), "BobPrivRSAEncrypt.p8e", 0)
If nChars > 0 Then Debug.Print Left(strTypeName, nChars)
  
strTypeName = String(PKI_ASN1_TYPE_MAXCHARS, " ")
nChars = ASN1_Type(strTypeName, Len(strTypeName), "rfc3280bis_CRL.crl", 0)
If nChars > 0 Then Debug.Print Left(strTypeName, nChars)
X509 CERTIFICATE
PKCS8 PRIVATE KEY INFO
PKCS8 ENCRYPTED PRIVATE KEY
X509 CRL

Example (VBA wrapper function)

Debug.Print asn1Type("AliceRSASignByCarl.cer", 0)
Debug.Print asn1Type("BobPrivRSAEncrypt.p8e", 0)
Debug.Print asn1Type("bad.file", 0)

See Also

ASN1_TextDump PEM_FileFromBinFile

[Contents] [Index]

[PREV: ASN1_TextDumpToString...]   [Contents]   [Index]   
   [NEXT: CIPHER_Bytes...]

Copyright © 2004-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-09-23T07:52:09Z.