dnauck / Portable.Licensing

Portable.Licensing is a cross platform software licensing framework which allows you to implement licensing into your application or library. It provides you all tools to create and validate licenses for your software.
http://dev.nauck-it.de/projects/portable-licensing
MIT License
592 stars 173 forks source link

Invalid Signature Validation #34

Closed thomasd3 closed 8 years ago

thomasd3 commented 8 years ago

I do not understand what I am doing wrong:

// make the keys
var KeyGenerator = Portable.Licensing.Security.Cryptography.KeyGenerator.Create();
var KeyPair = KeyGenerator.GenerateKeyPair();
var PrivateKey   = KeyPair.ToEncryptedPrivateKeyString(Common.ID_ENCRYPTION_KEY);
var PublicKey = KeyPair.ToPublicKeyString();

// make a license
var L = License.New()
    .WithUniqueIdentifier(Guid.NewGuid())
    .As(LicenseType.Standard)
    .ExpiresAt(DateTime.Now.AddDays(LICENSE_DAYS))
    .WithProductFeatures(new Dictionary<string, string>  
    {  
        { "Generated on", DateTime.UtcNow.ToString(CultureInfo.InvariantCulture) },
        { "ComputerId", ComputerId }
    }) 
    .CreateAndSignWithPrivateKey(PrivateKey, Common.ID_ENCRYPTION_KEY);

// save the license
using (var Writer = File.CreateText(LicenseFile))
{
    L.Save(Writer);
}

// reload the license
var LicenseText = File.ReadAllText(LicenseFile, Encoding.UTF8);
var L1 = License.Load(LicenseText);

// validate it
var ValidationFailures = L1.Validate().Signature(PublicKey).AssertValidLicense();
foreach (var Failure in ValidationFailures)
{
    Console.WriteLine(Failure.GetType().Name + ": " + Failure.Message + " - " + Failure.HowToResolve);
}

If I do this, it works. Now, if I change the writing of the license to

Console.WriteLine(L.tostring())

and I paste the text as the license file (a.txt in my example), I get an invalid signature validation... I feel that I missed something very simple somewhere :)

thomasd3 commented 8 years ago

I found the problem was really something stupid on my end; you can remove this issue.

blackchineykh commented 8 years ago

Hi Thomas. I am having the same issue, Can you say what was the issue?

thomasd3 commented 8 years ago

In my test code I had the save / load of the license as two functions and I was re-creating the key in between. As the key has a salt, even with the same passphrase, each execution will create a different key.