CryptoSys PKI Pro Manual

Rsa.ReadPublicKey Method

Read from a file or string containing a public key into an "internal" public key string.

Syntax

[C#]
public static StringBuilder ReadPublicKey(
   string certOrPublicKeyFile 
)
[VB]
Public Shared Function ReadPublicKey (
   certOrPublicKeyFile As String 
) As StringBuilder

Parameters

certOrPublicKeyFile  String
Name of X.509 certificate or public key file or a PEM String containing the key

Return Value

StringBuilder
StringBuilder containing an internal representation of the public key; or an empty StringBuilder if error

Remarks

This returns a StringBuilder, not a string. Use sb.ToString() to obtain a string.

Example

// Read an RSA public key and save in a different format
string pubkeyFile = "AlicePubRSA.pub";
StringBuilder sbPublicKey = Rsa.ReadPublicKey(pubkeyFile);
Debug.Assert(sbPublicKey.Length > 0, "Rsa.ReadPublicKey Failed");
int n = Rsa.SavePublicKey("AlicePubRSA_new", sbPublicKey.ToString(), Rsa.Format.SSL);
Console.WriteLine("Rsa.SavePublicKey returns {0} (expecting 0)", n);

See Also

VB6/C equivalent: RSA_ReadPublicKey

[Contents] [Index]

[PREV: Rsa.ReadPrivateKeyInfo Method...]   [Contents]   [Index]   
   [NEXT: Rsa.SaveEncKey Method...]

Copyright © 2004-26 D.I. Management Services Pty Ltd t/a CryptoSys. All rights reserved. Generated 2026-09-21T05:59:39Z.