public virtual string GenerateKey(string password, string productInfo, UInt16 serialNo)
{
// Public Key token for the Infralution signed assemblies
//
byte[] requiredToken = { 0x3E, 0x7E, 0x8E, 0x37, 0x44, 0xA5, 0xC1, 0x3F };
byte[] designKey = GetEncryptionKey(password);
byte[] productData = ASCIIEncoding.UTF8.GetBytes(productInfo);
byte[] clientData = BitConverter.GetBytes(serialNo);
byte[] payload = new byte[ArraySize(productData.Length + clientData.Length)];
byte[] publicKeyToken = Assembly.GetExecutingAssembly().GetName().GetPublicKeyToken();
byte[] testKey = { 0x3E, 0x7E, 0x8E, 0x37, 0x44, 0xA5, 0xC1, 0x3F };
clientData.CopyTo(payload, 0);
productData.CopyTo(payload, 2);
#if CHECK_PUBLIC_KEY
const string passwordErrorMsg = "The only allowable password in evaluation mode is 'TEST'";
const string serialNoErrorMsg = "The only allowable serial numbers in evaluation mode are '0' or '1'";
// if the Licensing System is not licensed then we need to check the password and client ID
//
if (SystemLicense == null)
{
if (password != "TEST")
throw new LicenseException(typeof(EncryptedLicenseProvider), this, passwordErrorMsg);
if (serialNo < 0 || serialNo > 1)
throw new LicenseException(typeof(EncryptedLicenseProvider), this, serialNoErrorMsg);
}
// 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 (!ArrayEqual(publicKeyToken, requiredToken))
{
_desKey.CopyTo(designKey, 0);
}
#endif
// encrypt the payload using the design key
//
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
des.Key = _desKey;
des.IV = designKey;
byte[] encPayload = des.CreateEncryptor().TransformFinalBlock(payload, 0, payload.Length);
// Combine the design key and encrypted payload
// Note that only the first 7 bytes of the key contain information so we
// only pack this much information - this enables us to reduce the size of
// the final key by 8 bytes.
//
byte[] data = new byte[ArraySize(keyLength + encPayload.Length)];
designKey.CopyTo(data, 0);
encPayload.CopyTo(data, keyLength);
// encrypt again to obscure the design key - this time using preset encryption key
//
des.IV = _desIV;
byte[] encData = des.CreateEncryptor().TransformFinalBlock(data, 0, data.Length);
return ToHex(encData);
}