Audience
This document is designed for people that are familiar with the concept of System Codes and, ideally, understand the use of Dynamic Parameters.
What are Encrypted Codes?
Encryption / Obfuscation
XOR | http://www.yoursite.com/page.php?id=[123456] | |
http://www.yoursite.com/page.php?userid=[%(uid)] | (with Dynamic Parameter uid) | |
Rijandael | http://www.yoursite.com/page.php?id={r:123456} | |
http://www.yoursite.com/page.php?id={r:%(uid)} | (with Dynamic Parameter uid) |
1: string XOR(string Key, string EncryptedContent)
2: {
3: StringBuilder sb = new StringBuilder();
4:
5: for (int i = 0; i < Key.Length && i < EncryptedContent.Length; i++)
6: sb.Append((char)(Key[i] ^ EncryptedContent [i]));
7:
8: return sb.ToString();
9: }
1: string DecryptRijandael(string Key, string EncryptedContent)
2: {
3: /* Constants */
4: byte[] salt = Encoding.ASCII.GetBytes("sumsumsum");
5: byte[] vector = Encoding.ASCII.GetBytes("@dddc3D41234g7H8");
6: const int iterations = 2;
7: const int keySize = 256;
8:
9: /* Preparing the encrypted string */
10: string encryptedContent = EncryptedContent.Replace("_", "+").Replace("-", "/");
11: int missing = encryptedContent.Length % 4 == 0 ? 0 : 4 - encryptedContent.Length % 4;
12:
13: for (int i = 0; i < missing; i++)
14: encryptedContent += "=";
15:
16: byte[] key = new Rfc2898DeriveBytes(Key, salt, iterations).GetBytes(keySize / 8);
17: byte[] encryptedContentBytes = System.Convert.FromBase64String(encryptedContent);
18: RijndaelManaged symmetricKey = new RijndaelManaged();
19: symmetricKey.Mode = CipherMode.CBC;
20: ICryptoTransform decryptor = symmetricKey.CreateDecryptor(key, vector);
21: MemoryStream memoryStream = new MemoryStream(encryptedContentBytes);
22: CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read);
23: byte[] plainTextBytesBuf = new byte[encryptedContentBytes.Length];
24: int decryptedByteCount = cryptoStream.Read(plainTextBytesBuf, 0, plainTextBytesBuf.Length);
25: memoryStream.Close();
26: cryptoStream.Close();
27: byte[] plainTextBytes = new byte[decryptedByteCount];
28: Array.Copy(plainTextBytesBuf, plainTextBytes, decryptedByteCount);
29:
30: return Encoding.UTF8.GetString(plainTextBytes);
31: }
Cost
Implementing Encrypted Codes is free and available for all existing and new System Codes.