public CipherTextDecryptionResult Decrypt(AsymmetricDecryptionArguments arguments) { var decryptionResult = new CipherTextDecryptionResult(); try { var cipher = new RSACryptoServiceProvider(); cipher.FromXmlString(arguments.FullAsymmetricKey.ToString()); byte[] original = cipher.Decrypt(Convert.FromBase64String(arguments.CipherText), false); decryptionResult.DecodedText = Encoding.UTF8.GetString(original); decryptionResult.Success = true; } catch (Exception ex) { decryptionResult.ExceptionMessage = ex.Message; } return decryptionResult; }
public CipherTextDecryptionResult Decrypt(AsymmetricDecryptionArguments arguments) { var decryptionResult = new CipherTextDecryptionResult(); try { var cipher = new RSACryptoServiceProvider(); cipher.FromXmlString(arguments.FullAsymmetricKey.ToString()); byte[] original = cipher.Decrypt(Convert.FromBase64String(arguments.CipherText), false); decryptionResult.DecodedText = Encoding.UTF8.GetString(original); decryptionResult.Success = true; } catch (Exception ex) { decryptionResult.ExceptionMessage = ex.Message; } return(decryptionResult); }
public void RsaAsymmetricCryptographyServiceEncryptDecryptTest() { var asymmetricSevice = new RsaAsymmetricCryptographyService(); var keyPairGenerationResult = asymmetricSevice.GenerateAsymmetricKeys(1024); Assert.AreEqual(true, keyPairGenerationResult.Success); var encryptionArgs = new AsymmetricEncryptionArguments { PlainText = "Text to be encrypted", PublicKeyForEncryption = keyPairGenerationResult.PublicKeyOnlyXml }; var encryptionResult = asymmetricSevice.Encrypt(encryptionArgs); Assert.AreEqual(true, encryptionResult.Success); var decryptionArguments = new AsymmetricDecryptionArguments() { CipherText = encryptionResult.CipherText, FullAsymmetricKey = keyPairGenerationResult.FullKeyPairXml }; var decryptionResult = asymmetricSevice.Decrypt(decryptionArguments); Assert.AreEqual(true, decryptionResult.Success); }