CryptoSys PKI Toolkit Manual

RSA_SavePrivateKeyInfo

Saves a private key string to an (unencrypted) PKCS-8 private key info file.

VB6/VBA Syntax

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

Parameters

strOutputFile
[in] String specifying the filename of the output file to be created.
strPrivateKey
[in] String containing the private key string
nOptions
[in] Long Option flags. Select one of:
PKI_DEFAULT (0) to export a binary BER-encoded file (default)
PKI_KEY_FORMAT_PEM to export a PEM-like "PRIVATE KEY" file
PKI_KEY_FORMAT_SSL to export an OpenSSL-compatible "RSA PRIVATE KEY" PEM file

C/C++ Syntax

long _stdcall RSA_SavePrivateKeyInfo(const char *szFileOut, const char *szKeyString, long nOptions);

Returns (VB6/C)

Long: If successful, the return value is zero; otherwise it returns a nonzero error code.

.NET Equivalent

Rsa.SavePrivateKeyInfo Method

Remarks

Caution: this data is saved in unencrypted form. Do not use for a production key.

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.

Example

    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.epk"
    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

See Also

RSA_ReadPrivateKeyInfo

[Contents] [Index]

[HOME]   [NEXT: RSA_SavePublicKey...]

Copyright © 2004-12 D.I. Management Services Pty Ltd. All rights reserved.