CryptoSys PKI Toolkit Manual

RSA_SavePublicKey

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

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

Parameters

strOutputFile
[in] String specifying the filename of the output file to be created.
strPublicKey
[in] String containing the public key string (or a private key string)
nOptions
[in] Long 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

C/C++ Syntax

long _stdcall RSA_SavePublicKey(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.SavePublicKey Method

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

[New in v3.7:] The OpenSSL format key is now saved with "Unix" line endings and a line length of strictly 64 characters. This is to help users in Portugal, but should not affect others.

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]

[HOME]   [NEXT: RSA_ToXMLString...]

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