Beispiel #1
0
 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)
         });
     }
 }
Beispiel #2
0
 private static IronDecryptResult DecryptWithCorrectDecryptionAlgorithm(byte[] toDecrypt, IronKeyResult key, ICryptoTransform encryption)
 {
     using (var memoryStream = new MemoryStream())
     {
         return(CreateCryptoStreamAndDecryptResult(toDecrypt, key, encryption, memoryStream));
     }
 }
Beispiel #3
0
 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));
     }
 }
Beispiel #4
0
        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
            });
        }
Beispiel #5
0
 private static IronEncryptResult EncryptWithCorrectEncryption(string toEncrypt, IronKeyResult key, ICryptoTransform encryption)
 {
     using (var memoryStream = new MemoryStream())
     {
         return(WriteEncryptionToMemoryStream(toEncrypt, key, encryption, memoryStream));
     }
 }