// Decryption Routine: Base64 -> AES -> Zlib private static byte[] Decrypt(uint uVer, uint uLen, uint uLenCompressed, uint dwBufferFlag, byte[] pSrc) { byte[] bits = BitConverter.GetBytes(dwBufferFlag); if (!((bits[3] & 1) != 0)) { byte[] aKey; byte[] aIV; // Get the AES Key/IV for transformation CipherKeys.GetKeyAndIV(uVer, uLenCompressed, out aKey, out aIV); // Decode the base64 encoded string pSrc = Convert.FromBase64String(Encoding.UTF8.GetString(pSrc)); // Decrypt the AES encrypted block AESCipher pCipher = new AESCipher(aKey, aIV); pCipher.TransformBlock(pSrc, 0, uLen, pSrc, 0); } else { // Decrypt the XOR encrypted block pSrc = EncryptXOR(uVer, pSrc, uLen, uLenCompressed); } if (bits[0] != 0) { return(ZlibStream.UncompressBuffer(pSrc)); } return(pSrc); }
// Encryption Routine: Zlib -> AES -> Base64 public static byte[] Encrypt(uint uVer, byte[] pSrc, uint dwBufferFlag, out uint uLen, out uint uLenCompressed, out uint uLenEncoded) { byte[] bits = BitConverter.GetBytes(dwBufferFlag); byte[] pEncrypted; if (bits[0] != 0) { pEncrypted = ZlibStream.CompressBuffer(pSrc); } else { pEncrypted = new byte[pSrc.Length]; Buffer.BlockCopy(pSrc, 0, pEncrypted, 0, pSrc.Length); } uLen = (uint)pSrc.Length; uLenCompressed = (uint)pEncrypted.Length; if (!((bits[3] & 1) != 0)) { byte[] aKey; byte[] aIV; // Get the AES Key/IV for transformation CipherKeys.GetKeyAndIV(uVer, uLenCompressed, out aKey, out aIV); // Perform AES block encryption AESCipher pCipher = new AESCipher(aKey, aIV); pCipher.TransformBlock(pEncrypted, 0, uLen, pEncrypted, 0); // Encode the encrypted data into a base64 encoded string pEncrypted = Encoding.UTF8.GetBytes(Convert.ToBase64String(pEncrypted)); } else { // Perform XOR block encryption pEncrypted = EncryptXOR(uVer, pEncrypted, uLen, uLenCompressed); } uLenEncoded = (uint)pEncrypted.Length; return(pEncrypted); }
// Decryption Routine: Base64 -> AES -> Zlib private static byte[] Decrypt(PackVersion version, uint size, uint sizeCompressed, Encryption flag, byte[] src) { if (flag.HasFlag(Encryption.Aes)) { // Get the AES Key/IV for transformation CipherKeys.GetKeyAndIV(version, sizeCompressed, out byte[] key, out byte[] iv); // Decode the base64 encoded string src = Convert.FromBase64String(Encoding.UTF8.GetString(src)); // Decrypt the AES encrypted block AESCipher pCipher = new AESCipher(key, iv); pCipher.TransformBlock(src, 0, size, src, 0); } else if (flag.HasFlag(Encryption.Xor)) { // Decrypt the XOR encrypted block src = EncryptXor(version, src, size, sizeCompressed); } return(flag.HasFlag(Encryption.Zlib) ? ZlibStream.UncompressBuffer(src) : src); }
// Encryption Routine: Zlib -> AES -> Base64 public static byte[] Encrypt(PackVersion version, byte[] src, Encryption flag, out uint size, out uint sizeCompressed, out uint sizeEncoded) { byte[] pEncrypted; if (flag.HasFlag(Encryption.Zlib)) { pEncrypted = ZlibStream.CompressBuffer(src); } else { pEncrypted = new byte[src.Length]; Buffer.BlockCopy(src, 0, pEncrypted, 0, src.Length); } size = (uint)src.Length; sizeCompressed = (uint)pEncrypted.Length; if (flag.HasFlag(Encryption.Aes)) { // Get the AES Key/IV for transformation CipherKeys.GetKeyAndIV(version, sizeCompressed, out byte[] key, out byte[] iv); // Perform AES block encryption var pCipher = new AESCipher(key, iv); pCipher.TransformBlock(pEncrypted, 0, size, pEncrypted, 0); // Encode the encrypted data into a base64 encoded string pEncrypted = Encoding.UTF8.GetBytes(Convert.ToBase64String(pEncrypted)); } else if (flag.HasFlag(Encryption.Xor)) { // Perform XOR block encryption pEncrypted = EncryptXor(version, pEncrypted, size, sizeCompressed); } sizeEncoded = (uint)pEncrypted.Length; return(pEncrypted); }