Exemplo n.º 1
0
        public byte[] Decrypt(SymmetricEncryptionParameters parameters, byte[] inData)
        {
            using (MemoryStream inDataStream = new MemoryStream(inData), outDataStream = new MemoryStream())
            {
                this.Decrypt(parameters, inDataStream, outDataStream);

                return(outDataStream.ToArray());
            }
        }
Exemplo n.º 2
0
        public void Decrypt(SymmetricEncryptionParameters parameters, Stream inStream, Stream outStream)
        {
            using (var algorithm = AlgorithmMap[parameters.Algorithm]())
            {
                var iv = ExtractIv(inStream, algorithm.IV.Length);

                using (var cryptor = algorithm.CreateDecryptor(parameters.Key, iv))
                    using (var cryptoStream = new CryptoStream(outStream, cryptor, CryptoStreamMode.Write))
                        inStream.CopyTo(cryptoStream);
            }
        }
Exemplo n.º 3
0
        internal FileEncryptor(
            ISymmetricEncryptor symmetricEncryptor,
            IEncryptionKeyGenerator encryptionKeyGenerator,
            IConfigurationProvider configurationProvider,
            IFileNameManager fileNameManager,
            EncryptionKeyInput encryptionKeyInput,
            string vaultName)
        {
            var key = encryptionKeyGenerator.Generate(encryptionKeyInput);

            this.parameters = new SymmetricEncryptionParameters
            {
                Algorithm = AlgorithmType.Aes,
                Mode      = CipherMode.CBC,
                Padding   = PaddingMode.PKCS7,
                Key       = key
            };

            this.symmetricEncryptor    = symmetricEncryptor;
            this.configurationProvider = configurationProvider;
            this.fileNameManager       = fileNameManager;
            this.vaultName             = vaultName;
        }