public Stream Decrypt(EncryptedStream cipherStream)
 {
     byte[] cipherBytes = cipherStream.GetBytes();
     byte[] iv = cipherStream.Iv;
     byte[] clearBytes = ProtectedData.Unprotect(cipherBytes, iv, DataProtectionScope.LocalMachine);
     return new MemoryStream(clearBytes);
 }
 public Stream Decrypt(EncryptedStream cipherStream)
 {
     byte[] cipherBytes = cipherStream.GetBytes();
     byte[] iv          = cipherStream.Iv;
     byte[] clearBytes  = ProtectedData.Unprotect(cipherBytes, iv, DataProtectionScope.LocalMachine);
     return(new MemoryStream(clearBytes));
 }
 public EncryptedStream Encrypt(Stream clearStream)
 {
     byte[] clearBytes = clearStream.ReadToEnd();
     byte[] iv = GenerateIv();
     byte[] cipherBytes = ProtectedData.Protect(clearBytes, iv, DataProtectionScope.LocalMachine);
     var result = new EncryptedStream(cipherBytes, iv);
     return result;
 }
        public EncryptedStream Encrypt(Stream clearStream)
        {
            byte[] clearBytes  = clearStream.ReadToEnd();
            byte[] iv          = GenerateIv();
            byte[] cipherBytes = ProtectedData.Protect(clearBytes, iv, DataProtectionScope.LocalMachine);
            var    result      = new EncryptedStream(cipherBytes, iv);

            return(result);
        }
Exemple #5
0
        public Stream Decrypt(EncryptedStream cipherStream)
        {
            _cipher.IV = cipherStream.Iv;

            using (ICryptoTransform transform = _cipher.CreateDecryptor())
            {
                byte[] cipherBytes = cipherStream.GetBytes();

                byte[] clearBytes = transform.TransformFinalBlock(cipherBytes, 0, cipherBytes.Length);

                return(new MemoryStream(clearBytes));
            }
        }
        public Stream Decrypt(EncryptedStream cipherStream)
        {
            _cipher.IV = cipherStream.Iv;

            using (ICryptoTransform transform = _cipher.CreateDecryptor())
            {
                byte[] cipherBytes = cipherStream.GetBytes();

                byte[] clearBytes = transform.TransformFinalBlock(cipherBytes, 0, cipherBytes.Length);

                return new MemoryStream(clearBytes);
            }
        }