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(SymmetricDecryptionArguments arguments) { var res = new CipherTextDecryptionResult(); try { var cipher = CreateCipher(arguments); cipher.IV = Convert.FromBase64String(arguments.InitialisationVectorBase64Encoded); ICryptoTransform cryptTransform = cipher.CreateDecryptor(); byte[] cipherTextBytes = Convert.FromBase64String(arguments.CipherTextBase64Encoded); byte[] plainText = cryptTransform.TransformFinalBlock(cipherTextBytes, 0, cipherTextBytes.Length); res.DecodedText = Encoding.UTF8.GetString(plainText); res.Success = true; } catch (Exception ex) { res.ExceptionMessage = ex.Message; } return res; }
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(SymmetricDecryptionArguments arguments) { var res = new CipherTextDecryptionResult(); try { var cipher = CreateCipher(arguments); cipher.IV = Convert.FromBase64String(arguments.InitialisationVectorBase64Encoded); ICryptoTransform cryptTransform = cipher.CreateDecryptor(); byte[] cipherTextBytes = Convert.FromBase64String(arguments.CipherTextBase64Encoded); byte[] plainText = cryptTransform.TransformFinalBlock(cipherTextBytes, 0, cipherTextBytes.Length); res.DecodedText = Encoding.UTF8.GetString(plainText); res.Success = true; } catch (Exception ex) { res.ExceptionMessage = ex.Message; } return(res); }