using System.Security.Cryptography;
private static string key = "NKu84HvQaPRr";
private static string encryptedValue = "G/jBikRLNfxTlr3WAL/iOg==";
private static string iv = "abcdef987654";
public static void Main()
Console.WriteLine(DecryptPHP(encryptedValue));
public static string HMACThing()
using (var hmacsha256 = new HMACSHA256(System.Text.ASCIIEncoding.UTF8.GetBytes("15081947")))
hmacsha256.ComputeHash(System.Text.ASCIIEncoding.UTF8.GetBytes("state_code=4"));
return ByteToString(hmacsha256.Hash);
static string ByteToString(byte[] buff)
for (int i = 0; i < buff.Length; i++)
sbinary += buff[i].ToString("X2");
public static string DecryptPHP(string encrypted)
byte[] encryptedBytes = Convert.FromBase64String(encryptedValue);
byte[] keyBytes = System.Text.ASCIIEncoding.UTF8.GetBytes(key);
byte[] keyBytesFixed = new byte[16];
keyBytes.CopyTo(keyBytesFixed, 0);
byte[] ivBytes = System.Text.ASCIIEncoding.UTF8.GetBytes(iv);
byte[] ivBytesFixed = new byte[16];
ivBytes.CopyTo(ivBytesFixed, 0);
return DecryptStringFromBytesAes(encryptedBytes, keyBytesFixed, ivBytesFixed);
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();