using System.Security.Cryptography;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Security;
public static void Main()
string token = "vR0BPcq8Q5brz02hMpMl5XqBNXF5ZZR+ZLdw3IpmExJUmIHFBIU84F7E4f2VYjL9RILbru0Utj3wXOA=";
string actualDecrypted = "cNWw--Til19eQmwvl6efPdOAWSaUKk7fh9eOAVPs12U";
string serviceToken = DecryptString(Convert.FromBase64String(token), "password1!");
Console.WriteLine(string.Format("Decrypted cookie = {0}", serviceToken));
Console.WriteLine(string.Format("Error: {0}", exp.Message));
private static string DecryptString(byte[] encrypted, string password)
byte[] ivFromEncrypted = Slice(encrypted, 0, 15);
byte[] encryptedText = Slice(encrypted, 16);
byte[] passwordBytes = Encoding.Default.GetBytes(password);
passwordBytes = SHA256.Create().ComputeHash(passwordBytes);
IBufferedCipher cipher = CipherUtilities.GetCipher("AES/CTR/NoPadding");
cipher.Init(false, new ParametersWithIV(new KeyParameter(passwordBytes), ivFromEncrypted));
decryptedBytes = cipher.DoFinal(encryptedText);
return Encoding.Default.GetString(decryptedBytes);
private static byte[] Slice(byte[] bytes, int start, int end)
byte[] split = new byte[end - start+1];
split[zeroCounter] = bytes[counter];
private static byte[] Slice(byte[] bytes, int start)
return Slice(bytes, start, bytes.Length-1);