Attribute VB_Name = "basCrPKI"
' $Id: basCrPKI.bas $

' This module contains the full list of declaration statements
' for the CryptoSys (tm) PKI Pro library.
' VB6/VBA version.
' Last updated:
'   $Date: 2020-10-16 21:37Z $
'   $Revision: 20.0.0 $

'************************* COPYRIGHT NOTICE*************************
' Copyright (c) 2002-25 DI Management Services Pty Limited.
' <https://di-mgt.com.au> <https://cryptosys.net>
' All rights reserved.
' This code may only be used by licensed users and in
' accordance with the licence conditions.
' The latest version of the CryptoSys PKI Toolkit and a licence
' may be obtained from <https://cryptosys.net/pki>.
' This copyright notice must always be left intact.
'****************** END OF COPYRIGHT NOTICE*************************

' USING WITH A 64-BIT VERSION OF MICROSOFT OFFICE
' -----------------------------------------------
' See the file `basCrPKI64.bas`. The changes are as follows.
' Edit each declaration statement by adding the keyword "PtrSafe" between
' "Public Declare" and "Function", e.g.
'    Public Declare PtrSafe Function PKI_ErrorCode Lib "diCrPKI.dll" () As Long
' Regex: s/Public Declare Function/Public Declare PtrSafe Function/g
' Do *NOT* change any data types to LongPtr or LongLong.

Option Explicit
Option Base 0

' CONSTANTS
Public Const ENCRYPT As Long = -1
Public Const DECRYPT As Long = 0
Public Const PKI_DIR_ENCRYPT As Long = -1
Public Const PKI_DIR_DECRYPT As Long = 0
' Maximum number of bytes in hash digest byte array
Public Const PKI_MAX_HASH_BYTES As Long = 64
Public Const PKI_SHA1_BYTES     As Long = 20
Public Const PKI_SHA224_BYTES   As Long = 28
Public Const PKI_SHA256_BYTES   As Long = 32
Public Const PKI_SHA384_BYTES   As Long = 48
Public Const PKI_SHA512_BYTES   As Long = 64
Public Const PKI_MD5_BYTES      As Long = 16
Public Const PKI_MD2_BYTES      As Long = 16
Public Const PKI_RMD160_BYTES   As Long = 20
Public Const PKI_BTC160_BYTES   As Long = 20
' Maximum number of hex characters in hash digest
Public Const PKI_MAX_HASH_CHARS As Long = 2 * PKI_MAX_HASH_BYTES
Public Const PKI_SHA1_CHARS     As Long = 2 * PKI_SHA1_BYTES
Public Const PKI_SHA224_CHARS   As Long = 2 * PKI_SHA224_BYTES
Public Const PKI_SHA256_CHARS   As Long = 2 * PKI_SHA256_BYTES
Public Const PKI_SHA384_CHARS   As Long = 2 * PKI_SHA384_BYTES
Public Const PKI_SHA512_CHARS   As Long = 2 * PKI_SHA512_BYTES
Public Const PKI_MD5_CHARS      As Long = 2 * PKI_MD5_BYTES
Public Const PKI_MD2_CHARS      As Long = 2 * PKI_MD2_BYTES
Public Const PKI_RMD160_CHARS   As Long = 2 * PKI_RMD160_BYTES
Public Const PKI_BTC160_CHARS   As Long = 2 * PKI_BTC160_BYTES
' Synonym retained for backwards compatibility
Public Const PKI_MAX_HASH_LEN   As Long = PKI_MAX_HASH_CHARS
' Encryption block sizes in bytes
Public Const PKI_BLK_TDEA_BYTES     As Long = 8
Public Const PKI_BLK_AES_BYTES      As Long = 16
' Key size in bytes
Public Const PKI_KEYSIZE_TDEA_BYTES As Long = 24
Public Const PKI_KEYSIZE_MAX_BYTES  As Long = 32
' Required size for RNG seed file
Public Const PKI_RNG_SEED_BYTES     As Long = 64
' Length of GUID string - added [v12.3]
Public Const PKI_RNG_GUID_CHARS     As Long = 36
' Maximum number of characters in an error message
Public Const PKI_MAX_ERROR_CHARS    As Long = 647

' CONSTANTS USED IN OPTION FLAGS
Public Const PKI_DEFAULT       As Long = 0

' Signature algorithms
Public Const PKI_SIG_SHA1RSA   As Long = &H0    ' default
Public Const PKI_SIG_MD5RSA    As Long = &H1
Public Const PKI_SIG_MD2RSA    As Long = &H2
Public Const PKI_SIG_SHA256RSA As Long = &H3
Public Const PKI_SIG_SHA384RSA As Long = &H4
Public Const PKI_SIG_SHA512RSA As Long = &H5
Public Const PKI_SIG_SHA224RSA As Long = &H6
' synonyms added [v12.0]
Public Const PKI_SIG_RSA_SHA1   As Long = &H0
Public Const PKI_SIG_RSA_SHA224 As Long = &H6
Public Const PKI_SIG_RSA_SHA256 As Long = &H3
Public Const PKI_SIG_RSA_SHA384 As Long = &H4
Public Const PKI_SIG_RSA_SHA512 As Long = &H5
Public Const PKI_SIG_RSA_MD5    As Long = &H1 ' [not recommended for new implementations]
' New in [v11.0] ...
Public Const PKI_SIG_ECDSA_SHA1   As Long = &H10
Public Const PKI_SIG_ECDSA_SHA224 As Long = &H20
Public Const PKI_SIG_ECDSA_SHA256 As Long = &H30
Public Const PKI_SIG_ECDSA_SHA384 As Long = &H40
Public Const PKI_SIG_ECDSA_SHA512 As Long = &H50
' New in [v12.0]...
Public Const PKI_SIG_RSA_PSS_SHA1   As Long = &HB0
Public Const PKI_SIG_RSA_PSS_SHA224 As Long = &HB6
Public Const PKI_SIG_RSA_PSS_SHA256 As Long = &HB3
Public Const PKI_SIG_RSA_PSS_SHA384 As Long = &HB4
Public Const PKI_SIG_RSA_PSS_SHA512 As Long = &HB5

' Safe curves for EdDSA - new in [v12.5]
Public Const PKI_SIG_ED25519 As Long = &HC0

'Safe curves for ECDH - new in [v12.5]
Public Const PKI_ECDH_X25519       As Long = &HD0

' Salt lengths for RSA-PSS - new in [v12.0]
Public Const PKI_PSS_SALTLEN_HLEN    As Long = &H0 ' default
Public Const PKI_PSS_SALTLEN_MAX     As Long = &H200000
Public Const PKI_PSS_SALTLEN_20      As Long = &H300000
Public Const PKI_PSS_SALTLEN_ZERO    As Long = &H400000

' MGF parameters for RSA-OAEP/PSS - new in [v12.0]
Public Const PKI_MGF_MGF1SHA1        As Long = &H800000

' PKCS#5 Password-based encryption algorithms
Public Const PKI_PBE_SHA_3DES  As Long = &H0    ' default
' Added in [v11.0] as simpler alternative to PKI_PBE_PBES2 + PKI_BC
Public Const PKI_PBE_PBKDF2_DESEDE3 As Long = &H1010&
Public Const PKI_PBE_PBKDF2_AES128  As Long = &H1020&
Public Const PKI_PBE_PBKDF2_AES192  As Long = &H1030&
Public Const PKI_PBE_PBKDF2_AES256  As Long = &H1040&
' These next 3 changed in [v11.0] (by adding 0x8000000)
Public Const PKI_PBE_MD5_DES As Long = &H8000001
Public Const PKI_PBE_MD2_DES As Long = &H8000002
Public Const PKI_PBE_SHA_DES As Long = &H8000003
' Synonym retained for backwards compatibility
Public Const PKI_PBES2_3DES  As Long = PKI_PBE_PBKDF2_DESEDE3
' Older alternative to specify PBES2 PBKDF2: Add PKI_BC_* option to specify encryption alg
Public Const PKI_PBE_PBES2   As Long = &H1000

' Message digest hash algorithms
Public Const PKI_HASH_SHA1     As Long = &H0  ' default
Public Const PKI_HASH_MD5      As Long = &H1
Public Const PKI_HASH_MD2      As Long = &H2
Public Const PKI_HASH_SHA256   As Long = &H3
Public Const PKI_HASH_SHA384   As Long = &H4
Public Const PKI_HASH_SHA512   As Long = &H5
Public Const PKI_HASH_SHA224   As Long = &H6
Public Const PKI_HASH_RMD160   As Long = &H7  ' RIPEMD160  - New in [v11.0]
Public Const PKI_HASH_BTC160   As Long = &H8  ' BITCOIN160 - New in [v11.0]
Public Const PKI_HASH_MODE_TEXT  As Long = &H10000
Public Const PKI_HASH_DOUBLE     As Long = &H20000  ' New in [v11.0]

' HMAC algorithms
' Added [v11.0] as convenient synonyms
Public Const PKI_HMAC_SHA1     As Long = &H0
Public Const PKI_HMAC_SHA224   As Long = &H6
Public Const PKI_HMAC_SHA256   As Long = &H3
Public Const PKI_HMAC_SHA384   As Long = &H4
Public Const PKI_HMAC_SHA512   As Long = &H5

' CONSTANTS USED IN RSA EXPONENT PARAMETER
Public Const PKI_RSAEXP_EQ_3       As Long = 0
Public Const PKI_RSAEXP_EQ_5       As Long = 1
Public Const PKI_RSAEXP_EQ_17      As Long = 2
Public Const PKI_RSAEXP_EQ_257     As Long = 3
Public Const PKI_RSAEXP_EQ_65537   As Long = 4

' Return values for RSA_CheckKey
Public Const PKI_VALID_PUBLICKEY   As Long = 1
Public Const PKI_VALID_PRIVATEKEY  As Long = 0

' Options for ECC Keys - New in [v12.5]
Public Const PKI_ECC_PRIVATE_KEY As Long = &H0
Public Const PKI_ECC_PUBLIC_KEY  As Long = &H1

' BIT FLAGS

' RSA key generation
Public Const PKI_KEYGEN_INDICATE   As Long = &H1000000
Public Const PKI_KEY_FORMAT_PEM    As Long = &H10000
Public Const PKI_KEY_FORMAT_SSL    As Long = &H20000
Public Const PKI_KEY_TYPE_PKCS8    As Long = &H40000    ' New in [v11.0]

Public Const PKI_PFX_STRONG_CERT   As Long = &H1000000  ' New in [v12.3]
Public Const PKI_PFX_PLAIN_CERT    As Long = &H2000000
Public Const PKI_PFX_CLONE_KEY     As Long = &H4000000
Public Const PKI_PFX_ALT_FORMAT    As Long = &H100000
Public Const PKI_PFX_P7CHAIN       As Long = &H400

Public Const PKI_CMS_FORMAT_BASE64  As Long = &H10000
Public Const PKI_CMS_EXCLUDE_CERTS    As Long = &H100
Public Const PKI_CMS_EXCLUDE_DATA     As Long = &H200
Public Const PKI_CMS_CERTS_ONLY       As Long = &H400
Public Const PKI_CMS_INCLUDE_ATTRS    As Long = &H800
Public Const PKI_CMS_ADD_SIGNTIME    As Long = &H1000
Public Const PKI_CMS_ADD_SMIMECAP    As Long = &H2000
Public Const PKI_CMS_ADD_SIGNINGCERT As Long = &H4000  ' New in [v12.4]
Public Const PKI_CMS_ADD_ALGPROTECT  As Long = &H8000  ' New in [v12.4]
Public Const PKI_CMS_NO_INFLATE   As Long = &H1000000
Public Const PKI_CMS_NO_OUTER     As Long = &H2000000
Public Const PKI_CMS_ALT_ALGID    As Long = &H4000000
Public Const PKI_CMS_BIGFILE      As Long = &H8000000

Public Const PKI_XML_RSAKEYVALUE   As Long = &H1
Public Const PKI_XML_EXCLPRIVATE   As Long = &H10
Public Const PKI_XML_REQPRIVATE    As Long = &H20
Public Const PKI_XML_HEXBINARY     As Long = &H100

Public Const PKI_EME_DEFAULT       As Long = &H0
Public Const PKI_EME_PKCSV1_5      As Long = &H0
Public Const PKI_EME_OAEP          As Long = &H10
Public Const PKI_EMSIG_DEFAULT     As Long = &H20
Public Const PKI_EMSIG_PKCSV1_5    As Long = &H20
Public Const PKI_EMSIG_DIGESTONLY  As Long = &H1000
Public Const PKI_EMSIG_DIGINFO     As Long = &H2000
Public Const PKI_EMSIG_ISO9796     As Long = &H100000

' X.509 Option flags
Public Const PKI_X509_FORMAT_PEM    As Long = &H10000
Public Const PKI_X509_FORMAT_BIN    As Long = &H20000
Public Const PKI_X509_REQ_KLUDGE   As Long = &H100000
Public Const PKI_X509_NO_TIMECHECK As Long = &H200000
Public Const PKI_X509_LATIN1       As Long = &H400000
Public Const PKI_X509_UTF8         As Long = &H800000
Public Const PKI_X509_AUTHKEYID   As Long = &H1000000
Public Const PKI_X509_NO_BASIC    As Long = &H2000000
Public Const PKI_X509_CA_TRUE     As Long = &H4000000
Public Const PKI_X509_VERSION1    As Long = &H8000000
Public Const PKI_X509_LDAP        As Long = &H1000
Public Const PKI_X509_DECIMAL     As Long = &H8000&     ' NB "&" at end

' Flags for X.509 Key Usage
Public Const PKI_X509_KEYUSAGE_DIGITALSIGNATURE  As Long = &H1
Public Const PKI_X509_KEYUSAGE_NONREPUDIATION    As Long = &H2
Public Const PKI_X509_KEYUSAGE_KEYENCIPHERMENT   As Long = &H4
Public Const PKI_X509_KEYUSAGE_DATAENCIPHERMENT  As Long = &H8
Public Const PKI_X509_KEYUSAGE_KEYAGREEMENT      As Long = &H10
Public Const PKI_X509_KEYUSAGE_KEYCERTSIGN       As Long = &H20
Public Const PKI_X509_KEYUSAGE_CRLSIGN           As Long = &H40
Public Const PKI_X509_KEYUSAGE_ENCIPHERONLY      As Long = &H80
Public Const PKI_X509_KEYUSAGE_DECIPHERONLY      As Long = &H100

' SPECIFIC X509 RETURN VALUES
' [v12.0] Changed from +1/-1 to proper error codes
Public Const PKI_X509_EXPIRED        As Long = 16   ' (EXPIRED_ERROR) CHANGED FROM -1 [v12.0]
Public Const PKI_X509_VERIFY_FAILURE As Long = 22   ' (SIGNATURE_ERROR) CHANGED FROM -1 [v12.0]
Public Const PKI_X509_REVOKED        As Long = 42   ' (REVOCATION_ERROR) CHANGED FROM +1 [v12.0]
Public Const PKI_X509_INVALID        As Long = 43   ' (CERT_PATH_ERROR) CHANGED FROM +1 [v12.0]
Public Const PKI_X509_VALID_NOW      As Long = 0
Public Const PKI_X509_VERIFY_SUCCESS As Long = 0

' RETURN VALUES FOR CNV_CheckUTF
Public Const PKI_CHRS_NOT_UTF8   As Long = 0
Public Const PKI_CHRS_ALL_ASCII  As Long = 1
Public Const PKI_CHRS_ANSI8      As Long = 2
Public Const PKI_CHRS_MULTIBYTE  As Long = 3

' Options for CNV_ByteEncoding
Public Const PKI_CNV_UTF8_FROM_LATIN1 As Long = &H1
Public Const PKI_CNV_LATIN1_FROM_UTF8 As Long = &H2

' Options for CNV_Num[To/From]Bytes. New in [v11.0]
Public Const PKI_CNV_BIG_ENDIAN    As Long = &H0    ' default
Public Const PKI_CNV_LITTLE_ENDIAN As Long = &H1

' FLAGS AND RETURN VALUES FOR X.509 AND CMS QUERY FUNCTIONS
Public Const PKI_QUERY_GETTYPE    As Long = &H100000
Public Const PKI_QUERY_NUMBER     As Long = 1
Public Const PKI_QUERY_STRING     As Long = 2

' OPTIONS FOR RNG FUNCTIONS
Public Const PKI_RNG_STRENGTH_112 As Long = &H0 ' default
Public Const PKI_RNG_STRENGTH_128 As Long = &H1

' Block cipher (BC) algorithm options
Public Const PKI_BC_TDEA    As Long = &H10  ' )
Public Const PKI_BC_DESEDE3 As Long = &H10  ' ) equiv. synonyms for Triple DES
Public Const PKI_BC_3DES    As Long = &H10  ' )
Public Const PKI_BC_AES128  As Long = &H20
Public Const PKI_BC_AES192  As Long = &H30
Public Const PKI_BC_AES256  As Long = &H40
' Block cipher mode options
Public Const PKI_MODE_ECB  As Long = &H0
Public Const PKI_MODE_CBC  As Long = &H100
Public Const PKI_MODE_OFB  As Long = &H200
Public Const PKI_MODE_CFB  As Long = &H300
Public Const PKI_MODE_CTR  As Long = &H400
' Added [v12.1] AEAD only
Public Const PKI_MODE_GCM  As Long = &H500

' Block cipher padding options
Public Const PKI_PAD_DEFAULT As Long = &H0
Public Const PKI_PAD_NOPAD  As Long = &H10000
Public Const PKI_PAD_PKCS5  As Long = &H20000
Public Const PKI_PAD_1ZERO  As Long = &H30000
' Added [v11.1]
Public Const PKI_PAD_AX923  As Long = &H40000
Public Const PKI_PAD_W3C    As Long = &H50000

' AEAD algorithms - added [v12.1]
Public Const PKI_AEAD_AES_128_GCM  As Long = &H520
Public Const PKI_AEAD_AES_192_GCM  As Long = &H530
Public Const PKI_AEAD_AES_256_GCM  As Long = &H540

' Block cipher option flags
Public Const PKI_IV_PREFIX  As Long = &H1000

' Key transport algorithms
Public Const PKI_KT_RSAES_PKCS As Long = &H0     ' Default
Public Const PKI_KT_RSAES_OAEP As Long = &H8000& ' added [v12.0]

' Key derivation functions
Public Const PKI_KDF_KDF2      As Long = &H0    ' Default

' ASN.1 utilities - added [v10.0]
Public Const PKI_ASN1_NOCOMMENTS As Long = &H100000
Public Const PKI_ASN1_ADDLEVELS  As Long = &H800000
Public Const PKI_ASN1_TYPE_MAXCHARS As Long = 64

' SIG functions
Public Const PKI_SIG_USEDIGEST     As Long = &H1000   ' added [v10.0]
Public Const PKI_SIG_DETERMINISTIC As Long = &H2000   ' added [v11.0]
Public Const PKI_SIG_ASN1DER       As Long = &H4000   ' added [v11.0], changed from 0x200000 [v12.0]

' SMIME functions - added [v10.0]
Public Const PKI_SMIME_ENCODE_BASE64 As Long = &H10000
Public Const PKI_SMIME_ENCODE_BINARY As Long = &H20000
Public Const PKI_SMIME_ADDX          As Long = &H100000

' Encoding options - added [v11.0]
Public Const PKI_ENCODE_HEX       As Long = &H30000
Public Const PKI_ENCODE_BASE64URL As Long = &H40000

' Wipefile options - added [v12.0]
Public Const PKI_WIPEFILE_DOD7   As Long = &H0  ' default
Public Const PKI_WIPEFILE_SIMPLE As Long = &H1

' General
Public Const PKI_GEN_PLATFORM As Long = &H40
Public Const PKI_GEN_LEGACY   As Long = &H8000000  ' Added [v11.0]


' FUNCTION DECLARATIONS

' CRYPTOGRAPHIC MESSAGE SYNTAX (CMS) FUNCTIONS
Public Declare Function CMS_MakeEnvData Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strFileIn As String, ByVal strCertList As String, ByVal strSeed As String, ByVal nSeedLen As Long, ByVal nOptions As Long) As Long
Public Declare Function CMS_MakeEnvDataFromString Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strDataIn As String, ByVal strCertList As String, ByVal strSeed As String, ByVal nSeedLen As Long, ByVal nOptions As Long) As Long
Public Declare Function CMS_ReadEnvData Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strFileIn As String, ByVal strCertFile As String, ByVal strPrivateKey As String, ByVal nOptions As Long) As Long
Public Declare Function CMS_ReadEnvDataToString Lib "diCrPKI.dll" (ByVal strDataOut As String, ByVal nDataLen As Long, ByVal strFileIn As String, ByVal strCertFile As String, ByVal strPrivateKey As String, ByVal nOptions As Long) As Long
Public Declare Function CMS_MakeSigData Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strFileIn As String, ByVal strCertList As String, ByVal strPrivateKey As String, ByVal nOptions As Long) As Long
Public Declare Function CMS_MakeSigDataFromString Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strDataIn As String, ByVal strCertList As String, ByVal strPrivateKey As String, ByVal nOptions As Long) As Long
Public Declare Function CMS_MakeSigDataFromSigValue Lib "diCrPKI.dll" (ByVal strFileOut As String, ByRef lpSigValue As Byte, ByVal nSigLen As Long, ByRef lpData As Byte, ByVal nDataLen As Long, ByVal strCertList As String, ByVal nOptions As Long) As Long
Public Declare Function CMS_MakeDetachedSig Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strHexDigest As String, ByVal strCertList As String, ByVal strPrivateKey As String, ByVal nOptions As Long) As Long
Public Declare Function CMS_ReadSigData Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strFileIn As String, ByVal nOptions As Long) As Long
Public Declare Function CMS_ReadSigDataToString Lib "diCrPKI.dll" (ByVal strDataOut As String, ByVal nDataLen As Long, ByVal strFileIn As String, ByVal nOptions As Long) As Long
Public Declare Function CMS_GetSigDataDigest Lib "diCrPKI.dll" (ByVal strHexDigest As String, ByVal nHexDigestLen As Long, ByVal strFileIn As String, ByVal strCertFile As String, ByVal nOptions As Long) As Long
Public Declare Function CMS_VerifySigData Lib "diCrPKI.dll" (ByVal strFileIn As String, ByVal strCertFile As String, ByVal strHexDigest As String, ByVal nOptions As Long) As Long
Public Declare Function CMS_QuerySigData Lib "diCrPKI.dll" (ByVal strDataOut As String, ByVal nDataLen As Long, ByVal strFileIn As String, ByVal strQuery As String, ByVal nOptions As Long) As Long
Public Declare Function CMS_QueryEnvData Lib "diCrPKI.dll" (ByVal strDataOut As String, ByVal nDataOutLen As Long, ByVal strFileIn As String, ByVal strQuery As String, ByVal nOptions As Long) As Long
' New in [v10.0]
Public Declare Function CMS_MakeComprData Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strFileIn As String, ByVal nOptions As Long) As Long
Public Declare Function CMS_ReadComprData Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strFileIn As String, ByVal nOptions As Long) As Long
' New in [v12.2]
Public Declare Function CMS_ReadEnvDataToBytes Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutBytes As Long, ByVal strFileIn As String, ByVal strCertFile As String, ByVal strPrivateKey As String, ByVal nOptions As Long) As Long
Public Declare Function CMS_ReadSigDataToBytes Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutBytes As Long, ByVal strFileIn As String, ByVal nOptions As Long) As Long
Public Declare Function CMS_MakeEnvDataFromBytes Lib "diCrPKI.dll" (ByVal strFileOut As String, ByRef lpInput As Byte, ByVal nInputLen As Long, ByVal strCertList As String, ByVal strSeed As String, ByVal nSeedLen As Long, ByVal nOptions As Long) As Long
Public Declare Function CMS_MakeSigDataFromBytes Lib "diCrPKI.dll" (ByVal strFileOut As String, ByRef lpInput As Byte, ByVal nInputLen As Long, ByVal strCertList As String, ByVal strPrivateKey As String, ByVal nOptions As Long) As Long

' RSA PUBLIC KEY FUNCTIONS
Public Declare Function RSA_MakeKeys Lib "diCrPKI.dll" (ByVal strPubKeyFile As String, ByVal strPvkKeyFile As String, ByVal nBits As Long, ByVal nExpFermat As Long, ByVal nTests As Long, ByVal nCount As Long, ByVal strPassword As String, ByVal strSeed As String, ByVal nSeedLen As Long, ByVal nOptions As Long) As Long
Public Declare Function RSA_SavePublicKey Lib "diCrPKI.dll" (ByVal strOutputFile As String, ByVal strPublicKey As String, ByVal nOptions As Long) As Long
Public Declare Function RSA_SaveEncPrivateKey Lib "diCrPKI.dll" (ByVal strOutputFile As String, ByVal strPrivateKey As String, ByVal nCount As Long, ByVal strPassword As String, ByVal nOptions As Long) As Long
Public Declare Function RSA_SavePrivateKeyInfo Lib "diCrPKI.dll" (ByVal strOutputFile As String, ByVal strPrivateKey As String, ByVal nOptions As Long) As Long
Public Declare Function RSA_GetPrivateKeyFromPFX Lib "diCrPKI.dll" (ByVal strOutputFile As String, ByVal strPfxFile As String, ByVal nOptions As Long) As Long
Public Declare Function RSA_ToXMLString Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutputLen As Long, ByVal strKeyString As String, ByVal nOptions As Long) As Long
Public Declare Function RSA_ToXMLStringEx Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strKeyString As String, ByVal strPrefix As String, ByVal nOptions As Long) As Long
Public Declare Function RSA_FromXMLString Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutputLen As Long, ByVal strXmlString As String, ByVal nOptions As Long) As Long
Public Declare Function RSA_KeyBits Lib "diCrPKI.dll" (ByVal strKey As String) As Long
Public Declare Function RSA_KeyBytes Lib "diCrPKI.dll" (ByVal strKey As String) As Long
Public Declare Function RSA_CheckKey Lib "diCrPKI.dll" (ByVal strKey As String, ByVal nOptions As Long) As Long
Public Declare Function RSA_KeyHashCode Lib "diCrPKI.dll" (ByVal strKeyString As String) As Long
Public Declare Function RSA_KeyMatch Lib "diCrPKI.dll" (ByVal strPrivateKey As String, ByVal strPublicKey As String) As Long
Public Declare Function RSA_PublicKeyFromPrivate Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strKeyString As String, ByVal nOptions As Long) As Long
Public Declare Function RSA_ReadAnyPrivateKey Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strKeyFile As String, ByVal strPassword As String, ByVal nOptions As Long) As Long
Public Declare Function RSA_ReadAnyPublicKey Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strKeyFile As String, ByVal nOptions As Long) As Long
Public Declare Function RSA_KeyValue Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strKeyString As String, ByVal strFieldName As String, ByVal nOptions As Long) As Long

' The following five functions are @deprecated - prefer RSA_ReadAnyPrivateKey or RSA_ReadAnyPublicKey.
Public Declare Function RSA_ReadEncPrivateKey Lib "diCrPKI.dll" (ByVal strPrivateKey As String, ByVal nKeyMaxLen As Long, ByVal strEpkFileName As String, ByVal strPassword As String, ByVal nOptions As Long) As Long
Public Declare Function RSA_ReadPrivateKeyInfo Lib "diCrPKI.dll" (ByVal strPrivateKey As String, ByVal nKeyMaxLen As Long, ByVal strPriFileName As String, ByVal nOptions As Long) As Long
Public Declare Function RSA_ReadPrivateKeyFromPFX Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strPfxFile As String, ByVal strPassword As String, ByVal nOptions As Long) As Long
Public Declare Function RSA_ReadPublicKey Lib "diCrPKI.dll" (ByVal strPublicKey As String, ByVal nKeyMaxLen As Long, ByVal strKeyFileName As String, ByVal nOptions As Long) As Long
Public Declare Function RSA_GetPublicKeyFromCert Lib "diCrPKI.dll" (ByVal strPublicKey As String, ByVal nKeyMaxLen As Long, ByVal strCertFileName As String, ByVal nOptions As Long) As Long

' "RAW" RSA ENCRYPTION/DECRYPTION FUNCTIONS
Public Declare Function RSA_RawPublic Lib "diCrPKI.dll" (ByRef lpData As Byte, ByVal nDataLen As Long, ByVal strPublicKey As String, ByVal nOptions As Long) As Long
Public Declare Function RSA_RawPrivate Lib "diCrPKI.dll" (ByRef lpData As Byte, ByVal nDataLen As Long, ByVal strPrivateKey As String, ByVal nOptions As Long) As Long
Public Declare Function RSA_EncodeMsg Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutputLen As Long, ByRef lpMessage As Byte, ByVal nMsgLen As Long, ByVal nOptions As Long) As Long
Public Declare Function RSA_DecodeMsg Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutputLen As Long, ByRef lpInput As Byte, ByVal nInputLen As Long, ByVal nOptions As Long) As Long
' New in [v12.0]
Public Declare Function RSA_Encrypt Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutBytes As Long, ByRef lpInput As Byte, ByVal nInputLen As Long, ByVal strPublicKeyFile As String, ByVal strParameters As String, ByVal nOptions As Long) As Long
Public Declare Function RSA_Decrypt Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutBytes As Long, ByRef lpInput As Byte, ByVal nInputLen As Long, ByVal strPrivateKeyFile As String, ByVal strPassword As String, ByVal strParameters As String, ByVal nOptions As Long) As Long

' ELLIPTIC CURVE CRYPTOGRAPHY FUNCTIONS
' New in [v11.0]
Public Declare Function ECC_MakeKeys Lib "diCrPKI.dll" (ByVal strPubKeyFile As String, ByVal strPriKeyFile As String, ByVal strCurveName As String, ByVal strPassword As String, ByVal strParams As String, ByVal nOptions As Long) As Long
Public Declare Function ECC_ReadKeyByCurve Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strHexKey As String, ByVal strCurveName As String, ByVal nOptions As Long) As Long
Public Declare Function ECC_ReadPrivateKey Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strKeyFileOrString As String, ByVal strPassword As String, ByVal nOptions As Long) As Long
Public Declare Function ECC_ReadPublicKey Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strKeyFileOrString As String, ByVal nOptions As Long) As Long
Public Declare Function ECC_SaveEncKey Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strIntKeyString As String, ByVal strPassword As String, ByVal strParams As String, ByVal nOptions As Long) As Long
Public Declare Function ECC_SaveKey Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strIntKeyString As String, ByVal nOptions As Long) As Long
Public Declare Function ECC_PublicKeyFromPrivate Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strIntKeyString As String, ByVal nOptions As Long) As Long
Public Declare Function ECC_QueryKey Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strIntKeyString As String, ByVal strQuery As String, ByVal nOptions As Long) As Long
Public Declare Function ECC_KeyHashCode Lib "diCrPKI.dll" (ByVal strKeyString As String) As Long
' New in [v12.5]
Public Declare Function ECC_DHSharedSecret Lib "diCrPKI.dll" (ByRef lpZZ As Byte, ByVal nOutBytes As Long, ByVal strIntPrivateKey As String, ByVal strIntPublicKey As String, ByVal nOptions As Long) As Long

' PFX (PKCS-12) FUNCTIONS
Public Declare Function PFX_MakeFile Lib "diCrPKI.dll" (ByVal strOutputFile As String, ByVal strCertFile As String, ByVal strKeyFile As String, ByVal strPassword As String, ByVal strFriendlyName As String, ByVal nOptions As Long) As Long
Public Declare Function PFX_VerifySig Lib "diCrPKI.dll" (ByVal strFileName As String, ByVal strPassword As String, ByVal nOptions As Long) As Long
    
' X.509 CERTIFICATE FUNCTIONS
Public Declare Function X509_MakeCertSelf Lib "diCrPKI.dll" (ByVal strNewCertFile As String, ByVal strEPKFile As String, ByVal nCertNum As Long, ByVal nYearsValid As Long, ByVal strDistName As String, ByVal strExtensions As String, ByVal KeyUsageFlags As Long, ByVal strPassword As String, ByVal nOptions As Long) As Long
Public Declare Function X509_MakeCert Lib "diCrPKI.dll" (ByVal strNewCertFile As String, ByVal strIssuerCertFile As String, ByVal strSubjectPubKeyFile As String, ByVal strIssuerPvkInfoFile As String, ByVal nCertNum As Long, ByVal nYearsValid As Long, ByVal strDistName As String, ByVal strExtensions As String, ByVal KeyUsageFlags As Long, ByVal strPassword As String, ByVal nOptions As Long) As Long
Public Declare Function X509_CertRequest Lib "diCrPKI.dll" (ByVal strReqFile As String, ByVal strEPKFile As String, ByVal strDistName As String, ByVal strExtensions As String, ByVal strPassword As String, ByVal nOptions As Long) As Long
Public Declare Function X509_VerifyCert Lib "diCrPKI.dll" (ByVal strCertToVerify As String, ByVal strIssuerCert As String, ByVal nOptions As Long) As Long
Public Declare Function X509_CertThumb Lib "diCrPKI.dll" (ByVal strCertFile As String, ByVal strHexHash As String, ByVal nHexHashLen As Long, ByVal nOptions As Long) As Long
Public Declare Function X509_CertIsValidNow Lib "diCrPKI.dll" (ByVal strCertFile As String, ByVal nOptions As Long) As Long
Public Declare Function X509_CertIssuedOn Lib "diCrPKI.dll" (ByVal strCertFile As String, ByVal strOutput As String, ByVal nOutputLen As Long, ByVal nOptions As Long) As Long
Public Declare Function X509_CertExpiresOn Lib "diCrPKI.dll" (ByVal strCertFile As String, ByVal strOutput As String, ByVal nOutputLen As Long, ByVal nOptions As Long) As Long
Public Declare Function X509_CertSerialNumber Lib "diCrPKI.dll" (ByVal strCertFile As String, ByVal strOutput As String, ByVal nOutputLen As Long, ByVal nOptions As Long) As Long
Public Declare Function X509_CertIssuerName Lib "diCrPKI.dll" (ByVal strCertFile As String, ByVal strOutput As String, ByVal nOutputLen As Long, ByVal strDelim As String, ByVal nOptions As Long) As Long
Public Declare Function X509_CertSubjectName Lib "diCrPKI.dll" (ByVal strCertFile As String, ByVal strOutput As String, ByVal nOutputLen As Long, ByVal strDelim As String, ByVal nOptions As Long) As Long
Public Declare Function X509_HashIssuerAndSN Lib "diCrPKI.dll" (ByVal strCertFile As String, ByVal strOutput As String, ByVal nOutputLen As Long, ByVal nOptions As Long) As Long
Public Declare Function X509_GetCertFromP7Chain Lib "diCrPKI.dll" (ByVal strOutputFile As String, ByVal strP7cFile As String, ByVal nIndex As Long, ByVal nOptions As Long) As Long
Public Declare Function X509_GetCertFromPFX Lib "diCrPKI.dll" (ByVal strOutputFile As String, ByVal strPfxFile As String, ByVal strPassword As String, ByVal nOptions As Long) As Long
Public Declare Function X509_KeyUsageFlags Lib "diCrPKI.dll" (ByVal strCertFile As String) As Long
Public Declare Function X509_QueryCert Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strFileIn As String, ByVal szQuery As String, ByVal nOptions As Long) As Long
Public Declare Function X509_ReadStringFromFile Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strCertFile As String, ByVal nOptions As Long) As Long
Public Declare Function X509_SaveFileFromString Lib "diCrPKI.dll" (ByVal strNewCertFile As String, ByVal strCertString As String, ByVal nOptions As Long) As Long
Public Declare Function X509_TextDump Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strCertFile As String, ByVal nOptions As Long) As Long
Public Declare Function X509_ValidatePath Lib "diCrPKI.dll" (ByVal strCertListOrP7File As String, ByVal strTrustedCert As String, ByVal nOptions As Long) As Long
' New in [v12.0]
Public Declare Function X509_TextDumpToString Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strCertFile As String, ByVal nOptions As Long) As Long
' New in [v12.1]
Public Declare Function X509_ReadCertStringFromP7Chain Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strP7cFile As String, ByVal nIndex As Long, ByVal nOptions As Long) As Long
Public Declare Function X509_ReadCertStringFromPFX Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strPfxFile As String, ByVal strPassword As String, ByVal nOptions As Long) As Long
' New in [v12.2]
Public Declare Function X509_GetCertCountInP7Chain Lib "diCrPKI.dll" (ByVal strP7cFile As String, ByVal nOptions As Long) As Long

' X509 CRL FUNCTIONS
Public Declare Function X509_MakeCRL Lib "diCrPKI.dll" (ByVal strCrlFile As String, ByVal strIssuerCert As String, ByVal strIssuerKeyFile As String, ByVal strPassword As String, ByVal strRevokedCertList As String, ByVal strExtensions As String, ByVal nOptions As Long) As Long
Public Declare Function X509_CheckCertInCRL Lib "diCrPKI.dll" (ByVal strCertFile As String, ByVal strCrlFile As String, ByVal strCRLIssuerCert As String, ByVal strDate As String, ByVal nOptions As Long) As Long

' ONLINE CERTIFICATE STATUS PROTOCOL (OCSP) FUNCTIONS
Public Declare Function OCSP_MakeRequest Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strIssuerCert As String, ByVal strCertFileOrSerialNum As String, ByVal strExtensions As String, ByVal nOptions As Long) As Long
Public Declare Function OCSP_ReadResponse Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strResponseFile As String, ByVal strIssuerCert As String, ByVal strExtensions As String, ByVal nOptions As Long) As Long

' TRIPLE DATA ENCRYPTION ALGORITHM (TDEA/3DES/TRIPLE DES) BLOCK CIPHER FUNCTIONS
' [@deprecated - use CIPHER_ functions]
Public Declare Function TDEA_BytesMode Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByRef lpInput As Byte, ByVal nDataLen As Long, ByRef lpKey As Byte, ByVal bEncrypt As Long, ByVal strMode As String, ByRef lpIV As Byte) As Long
Public Declare Function TDEA_HexMode Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal strInput As String, ByVal strKey As String, ByVal bEncrypt As Long, ByVal strMode As String, ByVal strIV As String) As Long
Public Declare Function TDEA_B64Mode Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal strInput As String, ByVal strKey As String, ByVal bEncrypt As Long, ByVal strMode As String, ByVal strIV As String) As Long
Public Declare Function TDEA_File Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strFileIn As String, ByRef lpKey As Byte, ByVal bEncrypt As Long, ByVal strMode As String, ByRef lpIV As Byte) As Long

' GENERIC BLOCK CIPHER FUNCTIONS
Public Declare Function CIPHER_Hex Lib "diCrPKI.dll" (ByVal fEncrypt As Long, ByVal strOutput As String, ByVal nOutChars As Long, ByVal strData As String, ByVal strKey As String, ByVal strIV As String, ByVal strAlgAndMode As String, ByVal nOptions As Long) As Long
Public Declare Function CIPHER_KeyWrap Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutBytes As Long, ByRef lpData As Byte, ByVal nDataLen As Long, ByRef lpKek As Byte, ByVal nKekLen As Long, ByVal nOptions As Long) As Long
Public Declare Function CIPHER_KeyUnwrap Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutBytes As Long, ByRef lpData As Byte, ByVal nDataLen As Long, ByRef lpKek As Byte, ByVal nKekLen As Long, ByVal nOptions As Long) As Long
' [The following two functions are @deprecated]
Public Declare Function CIPHER_Bytes Lib "diCrPKI.dll" (ByVal fEncrypt As Long, ByRef lpOutput As Byte, ByRef lpData As Byte, ByVal nDataLen As Long, ByRef lpKey As Byte, ByRef lpIV As Byte, ByVal strAlgAndMode As String, ByVal nOptions As Long) As Long
Public Declare Function CIPHER_File Lib "diCrPKI.dll" (ByVal fEncrypt As Long, ByVal strFileOut As String, ByVal strFileIn As String, ByRef lpKey As Byte, ByRef lpIV As Byte, ByVal strAlgAndMode As String, ByVal nOptions As Long) As Long
' New in [v11.1]
Public Declare Function CIPHER_EncryptBytes2 Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutBytes As Long, ByRef lpInput As Byte, ByVal nInputLen As Long, ByRef lpKey As Byte, ByVal nKeyLen As Long, ByRef lpIV As Byte, ByVal nIVLen As Long, ByVal strAlgModePad As String, ByVal nOptions As Long) As Long
Public Declare Function CIPHER_DecryptBytes2 Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutBytes As Long, ByRef lpInput As Byte, ByVal nInputLen As Long, ByRef lpKey As Byte, ByVal nKeyLen As Long, ByRef lpIV As Byte, ByVal nIVLen As Long, ByVal strAlgModePad As String, ByVal nOptions As Long) As Long
Public Declare Function CIPHER_FileEncrypt Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strFileIn As String, ByRef lpKey As Byte, ByVal nKeyLen As Long, ByRef lpIV As Byte, ByVal nIVLen As Long, ByVal strAlgModePad As String, ByVal nOptions As Long) As Long
Public Declare Function CIPHER_FileDecrypt Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strFileIn As String, ByRef lpKey As Byte, ByVal nKeyLen As Long, ByRef lpIV As Byte, ByVal nIVLen As Long, ByVal strAlgModePad As String, ByVal nOptions As Long) As Long
' New in [v12.1]
Public Declare Function CIPHER_EncryptAEAD Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutBytes As Long, ByRef lpInput As Byte, ByVal nInputLen As Long, ByRef lpKey As Byte, ByVal nKeyLen As Long, ByRef lpIV As Byte, ByVal nIVLen As Long, ByRef lpAAD As Byte, ByVal nAadLen As Long, ByVal nOptions As Long) As Long
Public Declare Function CIPHER_DecryptAEAD Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutBytes As Long, ByRef lpInput As Byte, ByVal nInputLen As Long, ByRef lpKey As Byte, ByVal nKeyLen As Long, ByRef lpIV As Byte, ByVal nIVLen As Long, ByRef lpAAD As Byte, ByVal nAadLen As Long, ByVal nOptions As Long) As Long
' New in [v12.5]
Public Declare Function CIPHER_EncryptHex Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strInputHex As String, ByVal strKeyHex As String, ByVal strIvHex As String, ByVal strAlgModePad As String, ByVal nOptions As Long) As Long
Public Declare Function CIPHER_DecryptHex Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strInputHex As String, ByVal strKeyHex As String, ByVal strIvHex As String, ByVal strAlgModePad As String, ByVal nOptions As Long) As Long

' MESSAGE DIGEST HASH FUNCTIONS
Public Declare Function HASH_HexFromBytes Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByRef lpMessage As Byte, ByVal nMsgLen As Long, ByVal nOptions As Long) As Long
' Alternative alias of HASH_HexFromBytes to cope with ANSI strings (VB6/VBA only)...
Public Declare Function HASH_HexFromString Lib "diCrPKI.dll" Alias "HASH_HexFromBytes" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strMessage As String, ByVal nMsgLen As Long, ByVal nOptions As Long) As Long
Public Declare Function HASH_HexFromFile Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strFileName As String, ByVal nOptions As Long) As Long
Public Declare Function HASH_Bytes Lib "diCrPKI.dll" (ByRef lpDigest As Byte, ByVal nDigLen As Long, ByRef lpMessage As Byte, ByVal nMsgLen As Long, ByVal nOptions As Long) As Long
Public Declare Function HASH_File Lib "diCrPKI.dll" (ByRef lpDigest As Byte, ByVal nDigLen As Long, ByVal strFileName As String, ByVal nOptions As Long) As Long
Public Declare Function HASH_HexFromHex Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nMaxChars As Long, ByVal strMsgHex As String, ByVal nOptions As Long) As Long
    
' HMAC FUNCTIONS
Public Declare Function HMAC_Bytes Lib "diCrPKI.dll" (ByRef lpDigest As Byte, ByVal nDigLen As Long, ByRef lpMessage As Byte, ByVal nMsgLen As Long, ByRef lpKey As Byte, ByVal nKeyLen As Long, ByVal nOptions As Long) As Long
Public Declare Function HMAC_HexFromBytes Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByRef lpMessage As Byte, ByVal nMsgLen As Long, ByRef lpKey As Byte, ByVal nKeyLen As Long, ByVal nOptions As Long) As Long
Public Declare Function HMAC_HexFromHex Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strMsgHex As String, ByVal strKeyHex As String, ByVal nOptions As Long) As Long

' ENCODING CONVERSION FUNCTIONS
' (See cnv* Functions below for VB6-friendly versions of these)
Public Declare Function CNV_HexStrFromBytes Lib "diCrPKI.dll" (ByVal strHex As String, ByVal nHexStrLen As Long, ByRef lpData As Byte, ByVal nDataLen As Long) As Long
Public Declare Function CNV_BytesFromHexStr Lib "diCrPKI.dll" (ByRef lpData As Byte, ByVal nDataLen As Long, ByVal strHex As String) As Long
Public Declare Function CNV_HexFilter Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal strInput As String, ByVal nStrLen As Long) As Long
Public Declare Function CNV_B64StrFromBytes Lib "diCrPKI.dll" (ByVal strB64 As String, ByVal nB64StrLen As Long, ByRef lpData As Byte, ByVal nDataLen As Long) As Long
Public Declare Function CNV_BytesFromB64Str Lib "diCrPKI.dll" (ByRef lpData As Byte, ByVal nDataLen As Long, ByVal strB64 As String) As Long
Public Declare Function CNV_B64Filter Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal strInput As String, ByVal nStrLen As Long) As Long

' BASE58 FUNCTIONS
' Added [v11.0]
Public Declare Function CNV_Base58FromBytes Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByRef lpInput As Byte, ByVal nInputLen As Long) As Long
Public Declare Function CNV_Base58ToBytes Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutBytes As Long, ByVal strInput As String) As Long
   
' UTF-8 CONVERSION/CHECK FUNCTIONS
Public Declare Function CNV_UTF8BytesFromLatin1 Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutBytes As Long, ByVal strInput As String) As Long
Public Declare Function CNV_Latin1FromUTF8Bytes Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByRef lpInput As Byte, ByVal nBytes As Long) As Long
Public Declare Function CNV_CheckUTF8Bytes Lib "diCrPKI.dll" (ByRef lpInput As Byte, ByVal nBytes As Long) As Long
Public Declare Function CNV_ByteEncoding Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutBytes As Long, ByRef lpInput As Byte, ByVal nBytes As Long, ByVal nOptions As Long) As Long
Public Declare Function CNV_CheckUTF8File Lib "diCrPKI.dll" (ByVal strFileName As String) As Long

' The following three functions are @deprecated...
Public Declare Function CNV_UTF8FromLatin1 Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strInput As String) As Long
Public Declare Function CNV_Latin1FromUTF8 Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strInput As String) As Long
Public Declare Function CNV_CheckUTF8 Lib "diCrPKI.dll" (ByVal strInput As String) As Long

' MISC BYTE UTILITIES
' Added [v11.0]
Public Declare Function CNV_ReverseBytes Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByRef lpInput As Byte, ByVal nBytes As Long) As Long
Public Declare Function CNV_NumToBytes Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutBytes As Long, ByVal nNumber As Long, ByVal nOptions As Long) As Long
Public Declare Function CNV_NumFromBytes Lib "diCrPKI.dll" (ByRef lpInput As Byte, ByVal nBytes As Long, ByVal nOptions As Long) As Long

' PEM/BINARY FILE CONVERSIONS
Public Declare Function PEM_FileFromBinFile Lib "diCrPKI.dll" (ByVal strOutputFile As String, ByVal strFileIn As String, ByVal strHeader As String, ByVal nLineLen As Long) As Long
Public Declare Function PEM_FileFromBinFileEx Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strFileIn As String, ByVal strHeader As String, ByVal nLineLen As Long, ByVal nOptions As Long) As Long
Public Declare Function PEM_FileToBinFile Lib "diCrPKI.dll" (ByVal strOutputFile As String, ByVal strFileIn As String) As Long

' ERROR FUNCTIONS
Public Declare Function PKI_LastError Lib "diCrPKI.dll" (ByVal strErrMsg As String, ByVal nMaxMsgLen As Long) As Long
' See also pkiGetLastError() below
Public Declare Function PKI_ErrorCode Lib "diCrPKI.dll" () As Long
Public Declare Function PKI_ErrorLookup Lib "diCrPKI.dll" (ByVal strErrMsg As String, ByVal nMaxMsgLen As Long, ByVal nErrorCode As Long) As Long
Public Declare Function PKI_PowerUpTests Lib "diCrPKI.dll" (ByVal nOptions As Long) As Long
    
' GENERAL DIAGNOSTIC FUNCTIONS
Public Declare Function PKI_Version Lib "diCrPKI.dll" (ByVal nReserved1 As Long, ByVal nReserved2 As Long) As Long
Public Declare Function PKI_LicenceType Lib "diCrPKI.dll" (ByVal nReserved As Long) As Long
Public Declare Function PKI_CompileTime Lib "diCrPKI.dll" (ByVal strCompiledOn As String, ByVal nStrLen As Long) As Long
Public Declare Function PKI_ModuleName Lib "diCrPKI.dll" (ByVal strModuleName As String, ByVal nStrLen As Long, ByVal nOptions As Long) As Long
Public Declare Function PKI_Platform Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long) As Long
' New in [v12.4]
Public Declare Function PKI_ModuleInfo Lib "diCrPKI.dll" (ByVal strModuleName As String, ByVal nStrLen As Long, ByVal nOptions As Long) As Long
    
' RNG FUNCTIONS
Public Declare Function RNG_Bytes Lib "diCrPKI.dll" (ByRef lpData As Byte, ByVal nDataLen As Long, ByVal strSeed As String, ByVal nSeedLen As Long) As Long
' Alternative alias of RNG_Bytes to write to an ANSI string (VB6/VBA only)...
Public Declare Function RNG_String Lib "diCrPKI.dll" Alias "RNG_Bytes" (ByVal strData As String, ByVal nDataLen As Long, ByVal strSeed As String, ByVal nSeedLen As Long) As Long
Public Declare Function RNG_Number Lib "diCrPKI.dll" (ByVal nLower As Long, ByVal nUpper As Long) As Long
Public Declare Function RNG_BytesWithPrompt Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutputLen As Long, ByVal strPrompt As String, ByVal nOptions As Long) As Long
' Alternative alias of RNG_BytesWithPrompt to write to an ANSI string (VB6/VBA only)...
Public Declare Function RNG_StringWithPrompt Lib "diCrPKI.dll" Alias "RNG_BytesWithPrompt" (ByVal strData As String, ByVal nDataLen As Long, ByVal strPrompt As String, ByVal nOptions As Long) As Long
Public Declare Function RNG_Initialize Lib "diCrPKI.dll" (ByVal strSeedFile As String, ByVal nOptions As Long) As Long
Public Declare Function RNG_MakeSeedFile Lib "diCrPKI.dll" (ByVal strSeedFile As String, ByVal strPrompt As String, ByVal nOptions As Long) As Long
Public Declare Function RNG_UpdateSeedFile Lib "diCrPKI.dll" (ByVal strSeedFile As String, ByVal nOptions As Long) As Long
Public Declare Function RNG_Test Lib "diCrPKI.dll" (ByVal strFileName As String, ByVal nOptions As Long) As Long
' New in [v12.3]
Public Declare Function RNG_Guid Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal nOptions As Long) As Long

' PASSWORD PROMPT FUNCTIONS
Public Declare Function PWD_Prompt Lib "diCrPKI.dll" (ByVal strPassword As String, ByVal nPwdlen As Long, ByVal strCaption As String) As Long
Public Declare Function PWD_PromptEx Lib "diCrPKI.dll" (ByVal strPassword As String, ByVal nPwdlen As Long, ByVal strCaption As String, ByVal strPrompt As String, ByVal nOptions As Long) As Long

' WIPE FUNCTIONS
Public Declare Function WIPE_File Lib "diCrPKI.dll" (ByVal strFileName As String, ByVal nOptions As Long) As Long
Public Declare Function WIPE_Data Lib "diCrPKI.dll" (ByRef lpData As Byte, ByVal nBytes As Long) As Long
' Alternative aliases of WIPE_Data to cope with Byte and String types explicitly (VB6/VBA only)...
Public Declare Function WIPE_Bytes Lib "diCrPKI.dll" Alias "WIPE_Data" (ByRef lpData As Byte, ByVal nBytes As Long) As Long
Public Declare Function WIPE_String Lib "diCrPKI.dll" Alias "WIPE_Data" (ByVal strData As String, ByVal nStrLen As Long) As Long

' PADDING FUNCTIONS
Public Declare Function PAD_BytesBlock Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutputLen As Long, ByRef lpInput As Byte, ByVal nInputLen As Long, ByVal nBlockLen As Long, ByVal nOptions As Long) As Long
Public Declare Function PAD_UnpadBytes Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutputLen As Long, ByRef lpInput As Byte, ByVal nInputLen As Long, ByVal nBlockLen As Long, ByVal nOptions As Long) As Long
Public Declare Function PAD_HexBlock Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nMaxChars As Long, ByVal strInputHex As String, ByVal nBlockLen As Long, ByVal nOptions As Long) As Long
Public Declare Function PAD_UnpadHex Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nMaxChars As Long, ByVal strInputHex As String, ByVal nBlockLen As Long, ByVal nOptions As Long) As Long

' PASSWORD-BASED KEY DERIVATION FUNCTIONS
Public Declare Function PBE_Kdf2 Lib "diCrPKI.dll" (ByRef lpKey As Byte, ByVal nKeyBytes As Long, ByRef lpPwd As Byte, ByVal nPwdBytes As Long, ByRef lpSalt As Byte, ByVal nSaltBytes As Long, ByVal nCount As Long, ByVal nReserved As Long) As Long
Public Declare Function PBE_Kdf2Hex Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nMaxChars As Long, ByVal nKeyBytes As Long, ByVal strPwd As String, ByVal strSaltHex As String, ByVal nCount As Long, ByVal nReserved As Long) As Long

' ASN.1 UTILITIES
Public Declare Function ASN1_TextDump Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strFileOrPEMString As String, ByVal nOptions As Long) As Long
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
' New in [v12.0]
Public Declare Function ASN1_TextDumpToString Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strFileOrPEMString As String, ByVal strDirName As String, ByVal nOptions As Long) As Long

' SIGNATURE FUNCTIONS
Public Declare Function SIG_SignData Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByRef lpData As Byte, ByVal nDataLen As Long, ByVal strKeyFile As String, ByVal strPassword As String, ByVal strAlgName As String, ByVal nOptions As Long) As Long
Public Declare Function SIG_SignFile Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strDataFile As String, ByVal strKeyFile As String, ByVal strPassword As String, ByVal strAlgName As String, ByVal nOptions As Long) As Long
Public Declare Function SIG_VerifyData Lib "diCrPKI.dll" (ByVal strSignature As String, ByRef lpData As Byte, ByVal nDataLen As Long, ByVal strCertOrKeyFile As String, ByVal strAlgName As String, ByVal nOptions As Long) As Long
Public Declare Function SIG_VerifyFile Lib "diCrPKI.dll" (ByVal strSignature As String, ByVal strDataFile As String, ByVal strCertOrKeyFile As String, ByVal strAlgName As String, ByVal nOptions As Long) As Long

' S/MIME FUNCTIONS
Public Declare Function SMIME_Wrap Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strFileIn As String, ByVal strFeatures As String, ByVal nOptions As Long) As Long
Public Declare Function SMIME_Extract Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strFileIn As String, ByVal nOptions As Long) As Long
Public Declare Function SMIME_Query Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strFileIn As String, ByVal strQuery As String, ByVal nOptions As Long) As Long

' COMPRESSION FUNCTIONS
' New in [v12.0]
Public Declare Function COMPR_Compress Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutBytes As Long, ByRef lpInput As Byte, ByVal nInputLen As Long, ByVal nOptions As Long) As Long
Public Declare Function COMPR_Uncompress Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutBytes As Long, ByRef lpInput As Byte, ByVal nInputLen As Long, ByVal nOptions As Long) As Long


' *** END OF CRYPTOSYS PKI DECLARATIONS

'**************************************************************************************
' SOME USEFUL WRAPPER FUNCTIONS

Public Function cnvHexStrFromBytes(abData() As Byte) As String
' Returns hex string encoding of bytes in abData or empty string if error
    Dim strHex As String
    Dim nHexLen As Long
    Dim nDataLen As Long
    
    On Error GoTo CatchEmptyData
    nDataLen = UBound(abData) - LBound(abData) + 1
    nHexLen = CNV_HexStrFromBytes(vbNullString, 0, abData(0), nDataLen)
    If nHexLen <= 0 Then
        Exit Function
    End If
    strHex = String$(nHexLen, " ")
    nHexLen = CNV_HexStrFromBytes(strHex, nHexLen, abData(0), nDataLen)
    If nHexLen <= 0 Then
        Exit Function
    End If
    cnvHexStrFromBytes = Left$(strHex, nHexLen)
    
CatchEmptyData:

End Function

Public Function cnvHexStrFromString(strData As String) As String
' Returns hex string encoding of ASCII string or empty string if error
    Dim strHex As String
    Dim nHexLen As Long
    Dim nDataLen As Long
    Dim abData() As Byte
    
    If Len(strData) = 0 Then Exit Function
    abData = StrConv(strData, vbFromUnicode)
    nDataLen = UBound(abData) - LBound(abData) + 1
    nHexLen = CNV_HexStrFromBytes(vbNullString, 0, abData(0), nDataLen)
    If nHexLen <= 0 Then
        Exit Function
    End If
    strHex = String$(nHexLen, " ")
    nHexLen = CNV_HexStrFromBytes(strHex, nHexLen, abData(0), nDataLen)
    If nHexLen <= 0 Then
        Exit Function
    End If
    cnvHexStrFromString = Left$(strHex, nHexLen)
End Function

Public Function cnvBytesFromHexStr(strHex As String) As Byte()
' Returns byte array decoded from a hex string
    Dim abData() As Byte
    Dim nDataLen As Long
    
    ' Set default return value that won't cause a run-time error
    cnvBytesFromHexStr = vbNullString
    nDataLen = CNV_BytesFromHexStr(0, 0, strHex)
    If nDataLen <= 0 Then
        Exit Function
    End If
    ReDim abData(nDataLen - 1)
    nDataLen = CNV_BytesFromHexStr(abData(0), nDataLen, strHex)
    If nDataLen <= 0 Then
        Exit Function
    End If
    ReDim Preserve abData(nDataLen - 1)
    cnvBytesFromHexStr = abData
End Function

Public Function cnvStringFromHexStr(ByVal strHex As String) As String
' Converts string <strHex> in hex format to string of ANSI chars
' with value between 0 and 255.
' E.g. "6162632E" will be converted to "abc."
    Dim abData() As Byte
    If Len(strHex) = 0 Then Exit Function
    abData = cnvBytesFromHexStr(strHex)
    cnvStringFromHexStr = StrConv(abData, vbUnicode)
End Function

Public Function cnvHexFilter(strHex As String) As String
' Returns a string stripped of any invalid hex characters
    Dim strFiltered As String
    Dim nLen As Long
    
    strFiltered = String(Len(strHex), " ")
    nLen = CNV_HexFilter(strFiltered, strHex, Len(strHex))
    If nLen > 0 Then
        strFiltered = Left$(strFiltered, nLen)
    Else
        strFiltered = ""
    End If
    cnvHexFilter = strFiltered
End Function

Public Function cnvB64StrFromBytes(abData() As Byte) As String
' Returns base64 string encoding of bytes in abData or empty string if error
    Dim strB64 As String
    Dim nB64Len As Long
    Dim nDataLen As Long
    
    On Error GoTo CatchEmptyData
    nDataLen = UBound(abData) - LBound(abData) + 1
    nB64Len = CNV_B64StrFromBytes(vbNullString, 0, abData(0), nDataLen)
    If nB64Len <= 0 Then
        Exit Function
    End If
    strB64 = String$(nB64Len, " ")
    nB64Len = CNV_B64StrFromBytes(strB64, nB64Len, abData(0), nDataLen)
    If nB64Len <= 0 Then
        Exit Function
    End If
    cnvB64StrFromBytes = Left$(strB64, nB64Len)
    
CatchEmptyData:

End Function

Public Function cnvB64StrFromString(strData As String) As String
' Returns base64 string encoding of ASCII string or empty string if error
    Dim strB64 As String
    Dim nB64Len As Long
    Dim nDataLen As Long
    Dim abData() As Byte
    
    If Len(strData) = 0 Then Exit Function
    abData = StrConv(strData, vbFromUnicode)
    nDataLen = UBound(abData) - LBound(abData) + 1
    nB64Len = CNV_B64StrFromBytes(vbNullString, 0, abData(0), nDataLen)
    If nB64Len <= 0 Then
        Exit Function
    End If
    strB64 = String$(nB64Len, " ")
    nB64Len = CNV_B64StrFromBytes(strB64, nB64Len, abData(0), nDataLen)
    If nB64Len <= 0 Then
        Exit Function
    End If
    cnvB64StrFromString = Left$(strB64, nB64Len)
End Function

Public Function cnvBytesFromB64Str(strB64 As String) As Byte()
' Returns byte array decoded from a base64 string
    Dim abData() As Byte
    Dim nDataLen As Long
    
    ' Set default return value that won't cause a run-time error
    cnvBytesFromB64Str = vbNullString
    nDataLen = CNV_BytesFromB64Str(0, 0, strB64)
    If nDataLen <= 0 Then
        Exit Function
    End If
    ReDim abData(nDataLen - 1)
    nDataLen = CNV_BytesFromB64Str(abData(0), nDataLen, strB64)
    If nDataLen <= 0 Then
        Exit Function
    End If
    ReDim Preserve abData(nDataLen - 1)
    cnvBytesFromB64Str = abData
End Function

Public Function cnvB64Filter(strB64 As String) As String
' Returns a string stripped of any invalid base64 characters
    Dim strFiltered As String
    Dim nLen As Long
    
    strFiltered = String(Len(strB64), " ")
    nLen = CNV_B64Filter(strFiltered, strB64, Len(strB64))
    If nLen > 0 Then
        strFiltered = Left$(strFiltered, nLen)
    Else
        strFiltered = ""
    End If
    cnvB64Filter = strFiltered
End Function

Public Function cnvB64StrFromHexStr(strHex As String)
' INPUT:  hex string representing a binary value
' OUTPUT: same value encoded in base64
    cnvB64StrFromHexStr = cnvB64StrFromBytes(cnvBytesFromHexStr(strHex))
End Function

Public Function cnvHexStrFromB64Str(strB64 As String)
' INPUT:  base64 string representing a binary value
' OUTPUT: same value encoded in hexadecimal
    cnvHexStrFromB64Str = cnvHexStrFromBytes(cnvBytesFromB64Str(strB64))
End Function

Public Function pkiGetLastError() As String
' Returns the last error message as a string, if any
    Dim sErrMsg As String
    Dim nLen As Long
    
    nLen = PKI_MAX_ERROR_CHARS
    sErrMsg = String$(nLen, " ")
    nLen = PKI_LastError(sErrMsg, nLen)
    pkiGetLastError = Left$(sErrMsg, nLen)
End Function

Public Function pkiErrorLookup(nErrCode As Long) As String
' Returns the error message for error code nErrCode
    Dim sErrMsg As String
    Dim nLen As Long
    
    nLen = PKI_MAX_ERROR_CHARS
    sErrMsg = String$(nLen, " ")
    nLen = PKI_ErrorLookup(sErrMsg, nLen, nErrCode)
    pkiErrorLookup = Left$(sErrMsg, nLen)
End Function

Public Function pwdPrompt(Optional sCaption As String) As String
    Dim sPassword As String
    Dim nLen As Long
    
    nLen = 255
    sPassword = String(nLen, " ")
    nLen = PWD_Prompt(sPassword, nLen, sCaption)
    If nLen < 0 Then
        Exit Function
    ElseIf nLen > 0 Then
        pwdPrompt = Left(sPassword, nLen)
    End If
    ' Clean up local variable
    Call WIPE_String(sPassword, nLen)
End Function

Public Function rsaReadPrivateKey(strKeyFileOrString As String, strPassword As String) As String
' Reads the private key from any supported private key file or PEM string
' Returns the key as an ephemeral base64 string or an empty string on error
    Dim nChars As Long
    ' How long is PrivateKey string?
    nChars = RSA_ReadAnyPrivateKey("", 0, strKeyFileOrString, strPassword, 0)
    If nChars <= 0 Then
        Exit Function
    End If
    ' Pre-dimension the string to receive data
    rsaReadPrivateKey = String(nChars, " ")
    ' Read in the Private Key
    nChars = RSA_ReadAnyPrivateKey(rsaReadPrivateKey, nChars, strKeyFileOrString, strPassword, 0)
End Function

Public Function rsaReadEncPrivateKey(strEPKFile As String, strPassword As String) As String
' Reads the private key from a PKCS-8 EncryptedPrivateKeyInfo file
' (as created by RSA_MakeKeys)
' Returns the key as a base64 string or an empty string on error
' @SUPERSEDED v10.0 by rsaReadPrivateKey
    Dim nLen As Long
    Dim lngRet As Long
    ' How long is PrivateKey string?
    nLen = RSA_ReadEncPrivateKey("", 0, strEPKFile, strPassword, 0)
    If nLen <= 0 Then
        Exit Function
    End If
    ' Pre-dimension the string to receive data
    rsaReadEncPrivateKey = String(nLen, " ")
    ' Read in the Private Key
    lngRet = RSA_ReadEncPrivateKey(rsaReadEncPrivateKey, nLen, strEPKFile, strPassword, 0)

End Function

Public Function rsaReadPublicKey(strKeyFile As String) As String
' Reads the public key from any supported public key file or PEM string
' Returns the key as an ephemeral base64 string or an empty string on error
    Dim nChars As Long
    ' How long is key string?
    nChars = RSA_ReadAnyPublicKey("", 0, strKeyFile, 0)
    If nChars <= 0 Then
        Exit Function
    End If
    ' Pre-dimension the string to receive data
    rsaReadPublicKey = String(nChars, " ")
    ' Read in the Public Key
    nChars = RSA_ReadAnyPublicKey(rsaReadPublicKey, nChars, strKeyFile, 0)
End Function

Public Function rsaReadPrivateKeyInfo(strKeyFile As String) As String
' Like rsaReadPrivateKey but for an UNencrypted private key info file
' Returns the key as a base64 string or an empty string on error
' @SUPERSEDED v10.0 by rsaReadPrivateKey
    Dim lngKeyLen As Long
    Dim lngRet As Long
    Dim strKey As String
    ' How long is key string?
    lngKeyLen = RSA_ReadPrivateKeyInfo("", 0, strKeyFile, 0)
    If lngKeyLen <= 0 Then
        Exit Function
    End If
    ' Pre-dimension the string to receive data
    strKey = String(lngKeyLen, " ")
    ' Read in the Private Key
    lngRet = RSA_ReadPrivateKeyInfo(strKey, lngKeyLen, strKeyFile, 0)
    rsaReadPrivateKeyInfo = strKey

End Function

Public Function rsaGetPublicKeyFromCert(strCertFile As String) As String
' Reads the public key from an X.509 certificate file
' Returns the key as a base64 string or an empty string on error
    Dim nLen As Long
    Dim lngRet As Long
    ' How long is key string?
    nLen = RSA_GetPublicKeyFromCert("", 0, strCertFile, 0)
    If nLen <= 0 Then
        Exit Function
    End If
    ' Pre-dimension the string to receive data
    rsaGetPublicKeyFromCert = String(nLen, " ")
    ' Read in the Private Key
    lngRet = RSA_GetPublicKeyFromCert(rsaGetPublicKeyFromCert, nLen, strCertFile, 0)

End Function

Public Function wipeString(ByRef strToWipe As String) As String
' Securely wipes a string and returns a blank string
' To call: strToWipe = wipeString(strToWipe)
    Call WIPE_String(strToWipe, Len(strToWipe))
    wipeString = ""
End Function

Public Function wipeBytes(ByRef abToWipe() As Byte)
    Call WIPE_Data(abToWipe(0), UBound(abToWipe) + 1)
    abToWipe = vbNullString
End Function

Public Function padHexString(ByVal strInputHex As String, nBlockLen As Long) As String
' Adds padding to a hex string up to next multiple of block length.
' Returns a padded hex string or, on error, an empty string.
    Dim nOutChars As Long
    Dim strOutputHex As String
    ' In VB6 an uninitialised empty string is passed to a DLL as a NULL,
    ' so we append a non-null empty string!
    strInputHex = strInputHex & ""
    nOutChars = PAD_HexBlock("", 0, strInputHex, nBlockLen, 0)
    Debug.Print "Required length is " & nOutChars & " characters"
    ' Check for error
    If (nOutChars <= 0) Then Exit Function
    ' Pre-dimension output
    strOutputHex = String(nOutChars, " ")
    nOutChars = PAD_HexBlock(strOutputHex, Len(strOutputHex), strInputHex, nBlockLen, 0)
    If (nOutChars <= 0) Then Exit Function
    Debug.Print "Padded data='" & strOutputHex & "'"
    padHexString = strOutputHex
End Function

Public Function unpadHexString(strInputHex As String, nBlockLen As Long) As String
' Strips padding from a hex string.
' Returns unpadded hex string or, on error, the original input string
' -- we do this because an empty string is a valid result.
' To check for error: a valid output string is *always* shorter than the input.
    Dim nOutChars As Long
    Dim strOutputHex As String
    ' No need to query for length because we know the output will be shorter than input
    ' so make sure output is as long as the input
    strOutputHex = String(Len(strInputHex), " ")
    nOutChars = PAD_UnpadHex(strOutputHex, Len(strOutputHex), strInputHex, nBlockLen, 0)
    Debug.Print "Unpadded length is " & nOutChars & " characters"
    ' Check for error
    If (nOutChars < 0) Then
        ' Return unchanged input to indicate error
        unpadHexString = strInputHex
        Exit Function
    End If
    ' Re-dimension the output to the correct length
    strOutputHex = Left$(strOutputHex, nOutChars)
    Debug.Print "Unpadded data='" & strOutputHex & "'"
    unpadHexString = strOutputHex
End Function

''' Returns a string containing the hex encoding of specified number of bytes from a byte array
Public Function cnvHexFromBytesMid(abData() As Byte, nOffset As Long, nBytes As Long) As String
    Dim strHex As String
    ' Lazy but safe! Encode it all then grab the substring
    strHex = cnvHexStrFromBytes(abData)
    cnvHexFromBytesMid = Mid(strHex, nOffset * 2 + 1, nBytes * 2)
End Function

' *** END OF USEFUL WRAPPER FUNCTIONS

' ... END OF MODULE
' *******************************************************************