Sample code for 30+ languages & platforms
C#

RSA Import Public Key from Certificate PEM

See more RSA Examples

Uses a certificate's public key for RSA encryption. The public key from the certificate .pem file is used.

Chilkat C# Downloads

C#
bool success = false;

Chilkat.Cert cert = new Chilkat.Cert();

success = cert.LoadFromFile("qa_data/pem/mf_public_rsa.pem");
if (success == false) {
    Debug.WriteLine(cert.LastErrorText);
    return;
}

Chilkat.PublicKey pubKey = new Chilkat.PublicKey();
cert.GetPublicKey(pubKey);

Chilkat.Rsa rsa = new Chilkat.Rsa();
rsa.UsePublicKey(pubKey);

rsa.EncodingMode = "base64";
string encryptedStr = rsa.EncryptStringENC("hello",false);
Debug.WriteLine("encrypted string = " + encryptedStr);