I am using this example that Brett gave:
And doing this:
public static bool VerifyLicenseKey(string applicationGuid)
{
Console.WriteLine("G: " + applicationGuid);
var appSettings = AppSettings.GetInstance();
if (appSettings == null)
{
return false;
}
var hwinfo = HardwareInfo.GetHardwareSerial();
Console.WriteLine("h: " + hwinfo);
Console.WriteLine("a: " + applicationGuid);
var currentSerial = Crypto.EncryptStringAES(hwinfo, applicationGuid);
Console.WriteLine("c: " + currentSerial);
Console.WriteLine("o: " + appSettings.LicenseSerialNumber);
if (currentSerial == appSettings.LicenseSerialNumber)
{
return true;
}
return false;
}
}
The GetHardwareSerial and applicationGuid are coming back the same every time but when I call the EncryptStringAES it is not.
Am I using the wrong class? Is it not suppose to be the same each time?
If not, does someone have a better example where the encryted values are the same?
The algorithm you’re referring to uses the RijndaelManaged class and it seems to be using the default value for its
IVproperty which is (quite rightly) automatically set to a new random value whenever you create a new instance (see documentation).Hence, you’ll get a different result every time. (You’ll find more about the purpose of the IV on Wikipedia, for example.)