Esempio n. 1
0
    static byte[] Decrypt(byte[] encryptedString)
    {
        using var provider = Aes.Create();
        provider.Key       = CryptoKey;
        using var ms       = new MemoryStream(encryptedString);
        // Read the first 16 bytes which is the IV.
        byte[] iv = new byte[16];
        ms.Read(iv, 0, 16);
        provider.IV = iv;

        using var decryptor = provider.CreateDecryptor();
        using var cs        = new CryptoStream(ms, decryptor, CryptoStreamMode.Read);
        return(cs.ReadAllBytes());
    }
Esempio n. 2
0
        byte[] Decrypt(byte[] encryptedString)
        {
            using (var provider = new AesCryptoServiceProvider())
            {
                provider.Key = EntityStateKey;
                using (var ms = new MemoryStream(encryptedString))
                {
                    // Read the first 16 bytes which is the IV.
                    byte[] iv = new byte[16];
                    ms.Read(iv, 0, 16);
                    provider.IV = iv;

                    using (var decryptor = provider.CreateDecryptor())
                    {
                        using (var cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read))
                        {
                            return(cs.ReadAllBytes());
                        }
                    }
                }
            }
        }