I'm trying to solve the problem in C# using .net framework cryptography and this is what try:
public static string GenerateCookie(string script)
{
var split = script.Split(new[] { "toNumbers(\"", "\")" }, StringSplitOptions.RemoveEmptyEntries)
.Where(s => s.Length == 32)
.ToArray();
if (split.Length != 3)
return null;
var key = StringToByteArray(split[0]);
var iv = StringToByteArray(split[1]);
var bytesIn = StringToByteArray(split[2]);
RijndaelManaged rijndael = new RijndaelManaged();
rijndael.KeySize = key.Length * 8;
rijndael.Padding = PaddingMode.None;
rijndael.Key = key;
rijndael.IV = iv;
rijndael.Mode = CipherMode.CBC;
var decrypter = rijndael.CreateDecryptor();
var decrypted = decrypter.TransformFinalBlock(bytesIn, 0, bytesIn.Length);
decrypter.Dispose();
rijndael.Dispose();
var hex = BitConverter.ToString(decrypted).Replace("-", "");
var expireTime = new string(script.Skip(script.IndexOf("expires="))
.TakeWhile(c => c != ';')
.ToArray())
.Replace("expires=", string.Empty);
if (string.IsNullOrEmpty(expireTime))
{
return null;
}
return string.Format("__test={0}; expires={1}; path=/", hex, expireTime);
}
And not worked, Also PaddingMode.PKCS7 give's me "Padding is invalid and cannot be removed" error.
Thanks.