internal EncryptedLicense GetLicense(string licenseKey, string password)
{
try
{
byte[] encData = FromHex(licenseKey);
byte[] requiredToken = { 0x3E, 0x7E, 0x8E, 0x37, 0x44, 0xA5, 0xC1, 0x3F };
byte[] publicKeyToken = Assembly.GetExecutingAssembly().GetName().GetPublicKeyToken();
// Validate this assembly - if it isn't signed with the correct public key
// then copy rubbish into the key. This is to make it just a little more
// difficult for the casual hacker.
//
#if CHECK_PUBLIC_KEY
if (!ArrayEqual(publicKeyToken, requiredToken))
{
_desKey.CopyTo(requiredToken, 0);
}
#endif
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
des.Key = _desKey;
des.IV = _desIV;
byte[] data = des.CreateDecryptor().TransformFinalBlock(encData, 0, encData.Length);
// extract the encryption key and encrypted product data - note that the encryption
// key has only 7 significant bytes
//
byte[] encryptionKey = new byte[ArraySize(8)];
byte[] encPayload = new byte[ArraySize(data.Length - keyLength)];
Array.Copy(data, 0, encryptionKey, 0, keyLength);
Array.Copy(data, keyLength, encPayload, 0, encPayload.Length);
// validate that the password matches that passed in
//
byte[] requiredEncryptionKey = GetEncryptionKey(password);
if (!ArrayEqual(encryptionKey, requiredEncryptionKey))
{
return null;
}
// decrypt the payload using the encryption key
//
des.IV = encryptionKey;
byte[] payload = des.CreateDecryptor().TransformFinalBlock(encPayload, 0, encPayload.Length);
byte[] productData = new byte[ArraySize(payload.Length - 2)];
Array.Copy(payload, 2, productData, 0, productData.Length);
UInt16 serialNo = BitConverter.ToUInt16(payload, 0);
string productInfo = System.Text.ASCIIEncoding.UTF8.GetString(productData);
return new EncryptedLicense(licenseKey, serialNo, productInfo);
}
catch
{
return null;
}
}