namespaceBookingBug{publicclassTokenGenerator{publicstaticstringcreate(JsonObjectdata){stringCompanyId="{Your Company ID or Affiliate ID}";stringSecureKey="{Your Secure Key}";stringinitVector="OpenSSL for Ruby";// DO NOT CHANGE// please change this as necessary to ensure that the SSO token is valid for 1 hour after this sciprt runsstringexpires=DateTime.UtcNow.AddHours(1).ToString("yyyy-MM-ddTHH:mm:ssZ");data["expires"]=expires;byte[]initVectorBytes=Encoding.UTF8.GetBytes(initVector);byte[]keyBytesLong;using(SHA1CryptoServiceProvidersha=newSHA1CryptoServiceProvider()){keyBytesLong=sha.ComputeHash(Encoding.UTF8.GetBytes(SecureKey+CompanyId));}byte[]keyBytes=newbyte[16];Array.Copy(keyBytesLong,keyBytes,16);byte[]textBytes=Encoding.UTF8.GetBytes(data.ToString());for(inti=0;i<16;i++){textBytes[i]^=initVectorBytes[i];}// Encrypt the string to an array of bytesbyte[]encrypted=encryptStringToBytes_AES(textBytes,keyBytes,initVectorBytes);stringencoded=Convert.ToBase64String(encrypted);returnHttpUtility.UrlEncode(encoded);}staticbyte[]encryptStringToBytes_AES(byte[]textBytes,byte[]Key,byte[]IV){// Declare the stream used to encrypt to an in memory// array of bytes and the RijndaelManaged object// used to encrypt the data.using(MemoryStreammsEncrypt=newMemoryStream())using(RijndaelManagedaesAlg=newRijndaelManaged()){// Provide the RijndaelManaged object with the specified key and IV.aesAlg.Mode=CipherMode.CBC;aesAlg.Padding=PaddingMode.PKCS7;aesAlg.KeySize=128;aesAlg.BlockSize=128;aesAlg.Key=Key;aesAlg.IV=IV;// Create an encrytor to perform the stream transform.ICryptoTransformencryptor=aesAlg.CreateEncryptor();// Create the streams used for encryption.using(CryptoStreamcsEncrypt=newCryptoStream(msEncrypt,encryptor,CryptoStreamMode.Write)){csEncrypt.Write(textBytes,0,textBytes.Length);csEncrypt.FlushFinalBlock();}byte[]encrypted=msEncrypt.ToArray();// Return the encrypted bytes from the memory stream.returnencrypted;}}}}classMainClass{staticvoidMain(string[]args){JsonObjectjsonObject=newJsonObject();jsonObject["first_name"]="John";jsonObject["last_name"]="Smith";jsonObject["email"]="smith@example.com";jsonObject["mobile"]="0123456789";jsonObject["reference"]="external-reference";System.Console.WriteLine(BookingBug.TokenGenerator.create(jsonObject));}}