Describes the type of ASN.1 data.
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)
long __stdcall ASN1_Type(char *szOutput, long nOutChars, const char *szFileOrPEMString, long nOptions);
If successful, the return value is the number of characters in or required for the output string; otherwise it returns a negative error code.
Public Function asn1Type
(szFileOrPEMString As String, Optional nOptions As Long = 0) As String
static std::string dipki::Asn1::Type (const std::string &asn1File)
static Asn1.type(asn1file)
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 value | ASN.1 object type | Reference |
---|---|---|
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 KEY | EncryptedPrivateKeyInfo | [RFC5208], [RFC5958] |
PKCS8 PRIVATE KEY INFO | PrivateKeyInfo | [RFC5208], [RFC5958] |
PKCS8 ONE ASYMMETRIC KEY | OneAsymmetricKey | [RFC5958] |
PUBLIC KEY INFO | SubjectPublicKeyInfo | [RFC3279], [RFC5480] |
X509 CERTIFICATE | Certificate | [RFC5280] |
X509 CRL | CertificateList | [RFC5280] |
Note that these descriptions are not necessarily those used as labels for PEM formatted files. See PEM_FileFromBinFile and [RFC7468].
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
Debug.Print asn1Type("AliceRSASignByCarl.cer", 0) Debug.Print asn1Type("BobPrivRSAEncrypt.p8e", 0) Debug.Print asn1Type("bad.file", 0)
ASN1_TextDump PEM_FileFromBinFile