CryptoSys PKI Pro Manual

RSA_SavePublicKey

Saves a public key string to PKCS-1 public key file.

VBA/VB6 Syntax

Public Declare Function RSA_SavePublicKey Lib "diCrPKI.dll" (ByVal strOutputFile As String, ByVal strPublicKey As String, ByVal nOptions As Long) As Long

nRet = RSA_SavePublicKey(strOutputFile, strPublicKey, nOptions) As Long

C/C++ Syntax

long __stdcall RSA_SavePublicKey(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 public key string (or a private key string)
nOptions
[in] Option flags. Select one of:
PKI_DEFAULT (0) to export a binary DER/BER-encoded file (default)
PKI_KEY_FORMAT_PEM to export a PEM-like "RSA PUBLIC KEY" file
PKI_KEY_FORMAT_SSL to export an OpenSSL-compatible "PUBLIC KEY" PEM file

Returns (VBA/C)

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

VBA Wrapper Syntax

Public Function rsaSaveKey (szOutputFile As String, szKeyStr As String, Optional nOptions As Long = 0) As Long

.NET Equivalent

Rsa.SavePublicKey Method

C++ (STL) Equivalent

static int dipki::Rsa::SaveKey (const std::string &outputFile, const std::string &keyStr, Format fileFormat=Format::Binary)

Remarks

Any existing file of the specified name will be overwritten without warning. Saves by default as binary DER/BER-encoded PKCS-1 RSAPublicKey data. The file saved with the PKI_KEY_FORMAT_PEM option is the same data in PEM format with header and footer lines:

 -----BEGIN RSA PUBLIC KEY-----
 -----END RSA PUBLIC KEY-----

The file saved with the PKI_KEY_FORMAT_SSL option is compatible with the format used by OpenSSL. The data is saved as X.509 SubjectPublicKeyInfo format encoded with header and footer lines:

 -----BEGIN PUBLIC KEY-----
 -----END PUBLIC KEY-----

The OpenSSL format key is saved with "Unix" line endings and a line length of strictly 64 characters.

You can use this function to extract a public key from a private key. Just pass the internal private key string instead of the public key string.

Example

See the example in RSA_GetPublicKeyFromCert.

See Also

RSA_ReadPublicKey RSA_GetPublicKeyFromCert

[Contents] [Index]

[PREV: RSA_SavePrivateKeyInfo...]   [Contents]   [Index]   
   [NEXT: RSA_ToXMLString...]

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