Anonymous Anonymous - 2 months ago
596 1

No description

C#

decrypt AES

string plaintext;
    string ciphertext;
    string decryptedtext;

    UTF8Encoding utf8 = new UTF8Encoding();

    AesCryptoServiceProvider aes = new AesCryptoServiceProvider();

 using (ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV))
    {
        MemoryStream ms = new MemoryStream();
        CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Write);
        byte[] bytes = Convert.FromBase64String(ciphertext);
        cs.Write(bytes, 0, bytes.Length);
        cs.FlushFinalBlock();
        ms.Position = 0;
        bytes = new byte[ms.Length];
        ms.Read(bytes, 0, bytes.Length);
        decryptedtext = utf8.GetString(bytes);
    }