Saves a private key string to an (unencrypted) PKCS-8 private key info file.
Public Declare Function RSA_SavePrivateKeyInfo Lib "diCrPKI.dll"
(ByVal strOutputFile As String, ByVal strPrivateKey As String,
ByVal nOptions As Long) As Long
nRet = RSA_SavePrivateKeyInfo(strOutputFile, strPrivateKey,
nOptions) As Long
long __stdcall RSA_SavePrivateKeyInfo(const char *szFileOut, const char *szKeyString, long nOptions);
PRIVATE KEY
fileRSA PRIVATE KEY
PEM fileIf successful, the return value is zero; otherwise it returns a nonzero error code.
static Rsa.save_key(outputfile, keystr, fileformat=0)
Any existing file of the specified name will be overwritten without warning. Saves by default as a binary BER-encoded file compatible with the PKCS-8 PrivateKeyInfo format. The PEM key format saved with the PKI_KEY_FORMAT_PEM option uses the header and footer lines:
-----BEGIN PRIVATE KEY----- -----END PRIVATE KEY-----
The OpenSSL-compatible PEM key format saved with the PKI_KEY_FORMAT_SSL option uses the header and footer lines:
-----BEGIN RSA PRIVATE KEY----- -----END RSA PRIVATE KEY-----
and is compatible with the PKCS-1 RSAPrivateKey format.
Dim strEPKFile As String Dim strPRIFile As String Dim strPEMFile As String Dim strPassword As String Dim strPrivateKey As String Dim nRet As Long strEPKFile = "rsa508.p8e" strPRIFile = "rsa508.pri" strPEMFile = "rsa508.pem" strPassword = "password" ' Read in the deciphered private key string strPrivateKey = rsaReadPrivateKey(strEPKFile, strPassword) If Len(strPrivateKey) = 0 Then MsgBox "Unable to retrieve private key" Exit Function End If Debug.Print strPrivateKey ' Save as unencrypted PrivateKeyInfo file nRet = RSA_SavePrivateKeyInfo(strPRIFile, strPrivateKey, 0) Debug.Print "RSA_SavePrivateKeyInfo returns " & nRet ' Save as unencrypted PEM-format file nRet = RSA_SavePrivateKeyInfo(strPEMFile, strPrivateKey, PKI_KEY_FORMAT_PEM) Debug.Print "RSA_SavePrivateKeyInfo returns " & nRet