public AsymmetricEncryptionResult Encrypt(AsymmetricEncryptionArguments arguments) { var encryptionResult = new AsymmetricEncryptionResult(); try { var myRSA = new RSACryptoServiceProvider(); var rsaKeyForEncryption = arguments.PublicKeyForEncryption.ToString(); myRSA.FromXmlString(rsaKeyForEncryption); byte[] data = Encoding.UTF8.GetBytes(arguments.PlainText); byte[] cipherText = myRSA.Encrypt(data, false); encryptionResult.CipherBytes = cipherText; encryptionResult.CipherText = Convert.ToBase64String(cipherText); encryptionResult.Success = true; } catch (Exception ex) { encryptionResult.ExceptionMessage = ex.Message; } return encryptionResult; }
public AsymmetricEncryptionResult Encrypt(AsymmetricEncryptionArguments arguments) { var encryptionResult = new AsymmetricEncryptionResult(); try { var myRSA = new RSACryptoServiceProvider(); var rsaKeyForEncryption = arguments.PublicKeyForEncryption.ToString(); myRSA.FromXmlString(rsaKeyForEncryption); byte[] data = Encoding.UTF8.GetBytes(arguments.PlainText); byte[] cipherText = myRSA.Encrypt(data, false); encryptionResult.CipherBytes = cipherText; encryptionResult.CipherText = Convert.ToBase64String(cipherText); encryptionResult.Success = true; } catch (Exception ex) { encryptionResult.ExceptionMessage = ex.Message; } return(encryptionResult); }