private static IronDecryptResult CreateCryptoStreamAndDecryptResult(byte[] toDecrypt, IronKeyResult key, ICryptoTransform encryption, MemoryStream memoryStream) { using (var cryptoStream = new CryptoStream(memoryStream, encryption, CryptoStreamMode.Write)) { cryptoStream.Write(toDecrypt, 0, toDecrypt.Length); cryptoStream.FlushFinalBlock(); var encrypted = memoryStream.ToArray(); return(new IronDecryptResult() { Key = key, DecryptedResult = System.Text.Encoding.UTF8.GetString(encrypted) }); } }
private static IronDecryptResult DecryptWithCorrectDecryptionAlgorithm(byte[] toDecrypt, IronKeyResult key, ICryptoTransform encryption) { using (var memoryStream = new MemoryStream()) { return(CreateCryptoStreamAndDecryptResult(toDecrypt, key, encryption, memoryStream)); } }
private static IronEncryptResult WriteEncryptionToMemoryStream(string toEncrypt, IronKeyResult key, ICryptoTransform encryption, MemoryStream memoryStream) { using (var cryptoStream = new CryptoStream(memoryStream, encryption, CryptoStreamMode.Write)) { return(WriteContentToCryptoStreamAndReturnEncryptedResult(toEncrypt, key, memoryStream, cryptoStream)); } }
private static IronEncryptResult WriteContentToCryptoStreamAndReturnEncryptedResult(string toEncrypt, IronKeyResult key, MemoryStream memoryStream, CryptoStream cryptoStream) { var bytesToEncrypt = System.Text.Encoding.UTF8.GetBytes(toEncrypt); cryptoStream.Write(bytesToEncrypt, 0, bytesToEncrypt.Length); cryptoStream.FlushFinalBlock(); var encrypted = memoryStream.ToArray(); return(new IronEncryptResult() { Key = key, EncryptedResult = encrypted }); }
private static IronEncryptResult EncryptWithCorrectEncryption(string toEncrypt, IronKeyResult key, ICryptoTransform encryption) { using (var memoryStream = new MemoryStream()) { return(WriteEncryptionToMemoryStream(toEncrypt, key, encryption, memoryStream)); } }