Sample code for 30+ languages & platforms
C#

Use Base64 RSA Key to Encrypt

See more RSA Examples

Loads a Base64 RSA key and uses it to encrypt a string, returning the result in base64.

Chilkat C# Downloads

C#
bool success = false;

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

Chilkat.PublicKey pubkey = new Chilkat.PublicKey();

success = pubkey.LoadBase64("MIICdgIBADA ... A9PXLk+j5A==");
if (success == false) {
    Debug.WriteLine(pubkey.LastErrorText);
    return;
}

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

success = rsa.UsePublicKey(pubkey);
if (success == false) {
    Debug.WriteLine(rsa.LastErrorText);
    return;
}

rsa.EncodingMode = "base64";

string encryptedStr = rsa.EncryptStringENC("12345678",false);

Debug.WriteLine(encryptedStr);