CryptoSys PKI Toolkit Manual

RSA_ReadPublicKey

RSA_ReadPublicKey reads from a BER-encoded public key file into an "internal" public key string.

VB6/VBA Syntax

Public Declare Function RSA_ReadPublicKey Lib "diCrPKI.dll" (ByVal strPublicKey As String, ByVal nOutChars As Long, ByVal strKeyFileName As String, ByVal nOptions As Long) As Long

nRet = RSA_ReadPublicKey(strPublicKey, nOutChars, strKeyFileName, nOptions) As Long

Parameters

strPrivateKey
[out] String to receive public key data in encoded "internal" format.
nOutChars
[in] Long specifying the maximum number of characters to be received.
strEpkFileName
[in] String specifying the filename of a public key file (or a string containing the data in PEM format).
nOptions
[in] Long option flags: not used in this release. Specify zero.

C/C++ Syntax

long _stdcall RSA_ReadPublicKey(char *szOutput, long nOutChars, const char *szKeyFile, long flags);

Returns (VB6/C)

Long: If successful, the return value is the number of characters in the output string; otherwise it returns a negative error code.

.NET Equivalent

Rsa.ReadPublicKey Method

Remarks

Only PKCS-1 RSAPublicKey files are supported. The file must be either in binary BER-encoded format or PEM format. Call the function with an empty or NULL strPublicKey string to find out the required length of the string. C/C++ users should add one to this value before allocating memory.

Example

This wrapper function returns the public key string given the filename

Public Function rsaReadPublicKey(strKeyFile As String) As String
  Dim nKeyLen As Long
  Dim nRet As Long
  ' How long is key string?
  nKeyLen = RSA_ReadPublicKey("", 0, strKeyFile, 0)
  If nKeyLen <= 0 Then
    Exit Function
  End If
  ' Pre-dimension the string to receive data
  rsaReadPublicKey = String(nKeyLen, " ")
  ' Read in the Private Key
  nRet = RSA_ReadPublicKey(rsaReadPublicKey, nKeyLen, strKeyFile, 0)
End Function

See Also

RSA_SavePublicKey RSA_GetPublicKeyFromCert

[Contents] [Index]

[HOME]   [NEXT: RSA_SaveEncPrivateKey...]

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