Exemplo n.º 1
0
 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));
 }
Exemplo n.º 3
0
 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);
        }
Exemplo n.º 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));
            }
        }
Exemplo n.º 6
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);
            }
        }