public LicenseBlob TryDeserialize(string license, string licenseSource, bool locallySourced)
        {
            LicenseBlob blob;

            try {
                blob = LicenseBlob.Deserialize(license);
            } catch (Exception ex) {
                AcceptIssue(new Issue("Failed to parse license (from " + licenseSource + "):",
                                      LicenseBlob.TryRedact(license) + "\n" + ex, IssueSeverity.Error));
                return(null);
            }
            if (!blob.VerifySignature(TrustedKeys, null))
            {
                sink.AcceptIssue(new Issue(
                                     "License " + blob.Fields.Id + " (from " + licenseSource +
                                     ") has been corrupted or has not been signed with a matching private key.", IssueSeverity.Error));
                return(null);
            }
            if (locallySourced && blob.Fields.MustBeFetched())
            {
                sink.AcceptIssue(new Issue(
                                     "This license cannot be installed directly; it must be fetched from a license server",
                                     LicenseBlob.TryRedact(license), IssueSeverity.Error));
                return(null);
            }
            return(blob);
        }
        static bool Validate(string licenseStr, BigInteger mod, BigInteger exp, StringBuilder log)
        {
            var blob = LicenseBlob.Deserialize(licenseStr);

            log?.AppendLine("---------------------------------------------");
            log?.AppendLine("Parsed info: " + blob.Fields);
            log?.AppendLine("Plaintext hash: " + BitConverter
                            .ToString(new SHA512Managed().ComputeHash(blob.Data))
                            .ToLower()
                            .Replace("-", ""));
            return(blob.VerifySignature(new[] { new RSADecryptPublic(mod, exp) }, log));
        }
        public static bool Revalidate(this ILicenseBlob b, IEnumerable <RSADecryptPublic> trustedKeys)
        {
            var ourCopy = LicenseBlob.Deserialize(b.Original);

            return(ourCopy.VerifySignature(trustedKeys, null) && ourCopy.Fields.DataMatches(b.Fields));
        }