Reads from a file or string containing a private key into an "internal" private key string.
Public Declare Function RSA_ReadAnyPrivateKey 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
nRet = RSA_ReadAnyPrivateKey(strOutput, nOutChars, strKeyFileOrString, strPassword, nOptions) As Long
long __stdcall RSA_ReadAnyPrivateKey(char *szOutput, long nOutChars, const char *szKeyFileOrString, const char *szPassword, long nOptions);
""
if not encrypted.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 rsaReadAnyPrivateKey
(szKeyFileOrString As String, Optional szPassword As String = "", Optional nOptions As Long = 0) As String
Public Function rsaReadPrivateKey
(szKeyFileOrString As String, Optional szPassword As String = "", Optional nOptions As Long = 0) As String
static std::string dipki::Rsa::ReadPrivateKey (const std::string &keyFileOrString, const std::string &password="")
static Rsa.read_private_key(keyfileorstr, password="")
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.
This function will attempt to read the private key from "any" supported format. The output will be an ephemeral "internal" key string suitable for the current session only.
Supported formats are:
RSAKeyPair
elementThis supersedes the following functions:
RSA_ReadEncPrivateKey
RSA_ReadPrivateKeyInfo
RSA_ReadPrivateKeyFromPFX
This VB6/VBA wrapper function returns the "internal" private key string given the filename and password
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
Dim strIntKey As String strIntKey = rsaReadAnyPrivateKey("AlicePrivRSASign.p8e", "password") Debug.Print strIntKey Debug.Print "KeyHashCode=0x" & Hex(RSA_KeyHashCode(strIntKey)) ' Unencrypted key strIntKey = rsaReadAnyPrivateKey("AlicePrivRSASign.pri", "") Debug.Print strIntKey Debug.Print "KeyHashCode=0x" & Hex(RSA_KeyHashCode(strIntKey)) ' Key in XML form strIntKey = rsaReadAnyPrivateKey("alice-pri.xml", "") Debug.Print strIntKey Debug.Print "KeyHashCode=0x" & Hex(RSA_KeyHashCode(strIntKey))