private void RSAPublic() { var bob = new RSAPrivKeyClient(); var pk = bob.PublicParameters; var alice = new RSAPubKeyClient(pk); var encrypted = alice.Encrypt(new byte[] { 0, 1, 2, 3 }); var decrypted = bob.Decrypt(encrypted); Console.WriteLine(decrypted); }
public string RSAEncrypt(string plainText) { // Get the bytes of the string byte[] bytesToBeEncrypted = Encoding.UTF8.GetBytes(plainText); RSAPrivKeyClient rSAPrivKeyClient = new RSAPrivKeyClient(); var pk = rSAPrivKeyClient.PublicParameters; RSAPubKeyClient rSAPubKeyClient = new RSAPubKeyClient(pk); var encrypted = rSAPubKeyClient.Encrypt(bytesToBeEncrypted); string result = Convert.ToBase64String(encrypted); return(result); }