System.Security.Cryptography.AesCryptoServiceProvider.CreateDecryptor C# (CSharp) Метод

CreateDecryptor() публичный Метод

public CreateDecryptor ( ) : ICryptoTransform
Результат ICryptoTransform
        public override ICryptoTransform CreateDecryptor() => _impl.CreateDecryptor();
        public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV) => _impl.CreateDecryptor(rgbKey, rgbIV);

Same methods

AesCryptoServiceProvider::CreateDecryptor ( byte rgbKey, byte rgbIV ) : ICryptoTransform

Usage Example

Пример #1
0
        static Dictionary<string, string> Decrypt(string cipherText, string encryptionPassword, string salt)
        {
            using (var algorithm = new AesCryptoServiceProvider
            {
                Key =GetEncryptionKey(encryptionPassword),
                IV = Convert.FromBase64String(salt)
            })
            using (var decryptor = algorithm.CreateDecryptor())
            using (var decryptedTextStream = new MemoryStream())
            using (var stringReader = new StreamReader(decryptedTextStream, Encoding.UTF8))
            using (var jsonReader = new JsonTextReader(stringReader))
            {
                try
                {
                    using (var cryptoStream = new CryptoStream(decryptedTextStream, decryptor, CryptoStreamMode.Write))
                    {
                        var cipherTextBytes = Convert.FromBase64String(cipherText);
                        cryptoStream.Write(cipherTextBytes, 0, cipherTextBytes.Length);
                        cryptoStream.FlushFinalBlock();

                        var dictionary = new Dictionary<string, string>();
                        var serializer = new JsonSerializer();
                        decryptedTextStream.Position = 0;
                        serializer.Populate(jsonReader, dictionary);
                        return dictionary;
                    }
                }
                catch (CryptographicException cryptoException)
                {
                    throw new CommandException(
                        "Cannot decrypt sensitive-variables. Check your password is correct.\nError message: " +
                        cryptoException.Message);
                }
            }
        }
All Usage Examples Of System.Security.Cryptography.AesCryptoServiceProvider::CreateDecryptor