using System.Security.Cryptography;
private static string key = "12345678901234567890123456789012";
private static string originalText = "does this work";
private static string encryptedValue = "a64d63874ba9ee8f5a5028cb40ab70a4yFFQwLuOHeWouyfp0dyrnw==";
public static void Main()
Console.WriteLine(DecryptPHP(encryptedValue));
public static string DecryptPHP(string encrypted)
var salt = encryptedValue.Substring(0, 32);
var unsaltedEncryptedValue = encryptedValue.Substring(32);
Console.WriteLine("salt: " + salt);
Console.WriteLine("unsaltedEncryptedValue: " + unsaltedEncryptedValue);
byte[] encryptedBytes = Convert.FromBase64String(unsaltedEncryptedValue);
byte[] unsaltedEncryptedBytes = System.Text.ASCIIEncoding.UTF8.GetBytes(unsaltedEncryptedValue);
byte[] keyBytes = System.Text.ASCIIEncoding.UTF8.GetBytes(key);
byte[] ivBytes = System.Text.ASCIIEncoding.UTF8.GetBytes(salt);
return DecryptStringFromBytesAes(unsaltedEncryptedBytes, keyBytes, ivBytes);
public static string DecryptStringFromBytesAes(byte[] cipherText, byte[] key, byte[] iv)
if (cipherText == null || cipherText.Length <= 0)
throw new ArgumentNullException("cipherText");
if (key == null || key.Length <= 0)
throw new ArgumentNullException("key");
if (iv == null || iv.Length <= 0)
throw new ArgumentNullException("iv");
RijndaelManaged aesAlg = null;
aesAlg = new RijndaelManaged { Mode = CipherMode.CBC, Padding = PaddingMode.Zeros, KeySize = 256, BlockSize = 128, Key = key, IV = iv };
ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
using (MemoryStream msDecrypt = new MemoryStream(cipherText))
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
using (StreamReader srDecrypt = new StreamReader(csDecrypt))
plaintext = srDecrypt.ReadToEnd();