示例#1
0
        public static LicenseContainer Sign(License license, string key)
        {
            license.SignatureUtcTime = DateTime.UtcNow;
            byte[] originalData = Encoding.Unicode.GetBytes(license.ToJson(Formatting.None));
            byte[] signedData;
            RSACryptoServiceProvider pro = new RSACryptoServiceProvider();

            pro.FromXmlString(key);
            signedData = pro.SignData(originalData, new SHA1CryptoServiceProvider());
            return(new LicenseContainer
            {
                Signature = Convert.ToBase64String(signedData),
            }.Set(license));


            // Export the key information to an RSAParameters object.
            // You must pass true to export the private key for signing.
            // However, you do not need to export the private key
            // for verification.
            //RSAParameters Key = pro.ExportParameters(true);

            // Sign
            //signedData = pro.SignData(originalData, new SHA1CryptoServiceProvider());
            //=> Sign(content, Convert.FromBase64String(key));
        }
示例#2
0
        public static LicenseContainer Sign(License license, byte[] key)
        {
            license.SignatureUtcTime = DateTime.UtcNow;
            var sign = CryptographicEngine.Sign(
                AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgorithm.RsaSignPssSha512).ImportKeyPair(key),
                Encoding.Unicode.GetBytes(license.ToJson(Formatting.None)));

            return(new LicenseContainer
            {
                Signature = Convert.ToBase64String(sign),
            }.SetLicense(license));
        }
示例#3
0
 public LicenseContainer SetLicense(License license)
 {
     License = new JRaw(license.ToJson(Formatting.None)); return(this);
 }