CryptoSys PKI Pro Manual

RSA_SavePrivateKeyInfo

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

VBA/VB6 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

C/C++ Syntax

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

Parameters

szFileOut
[in] specifying the filename of the output file to be created.
szKeyString
[in] containing the private key string
nOptions
[in] 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
and optionally add

Returns (VBA/C)

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

.NET Equivalent

Rsa.SavePrivateKeyInfo Method

Python Equivalent

static Rsa.save_key(outputfile, keystr, fileformat=0)

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

See Also

RSA_ReadPrivateKeyInfo

[Contents] [Index]

[PREV: RSA_SaveEncPrivateKey...]   [Contents]   [Index]   
   [NEXT: RSA_SavePublicKey...]

Copyright © 2004-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-09-23T07:52:09Z.