Beispiel #1
0
        public static bool VerifySignature(this ILicenseBlob b, IEnumerable <RSADecryptPublic> trustedKeys, StringBuilder log)
        {
            return(trustedKeys.Any(p =>
            {
                var signature = b.Signature();
                var hash = new SHA512Managed().ComputeHash(b.Data());
                var decrypted_bytes = p.DecryptPublic(signature);
                var valid = hash.SequenceEqual(decrypted_bytes);

                if (log != null)
                {
                    log.AppendLine("Using public exponent " + p.Exponent.ToString() + " and modulus " + p.Modulus.ToString());
                    log.AppendLine("Encrypted bytes: " + BitConverter.ToString(signature).ToLower().Replace("-", ""));
                    log.AppendLine("Decrypted sha512: " + BitConverter.ToString(decrypted_bytes).ToLower().Replace("-", ""));
                    log.AppendLine("Expected sha512: " + BitConverter.ToString(hash).ToLower().Replace("-", ""));
                    log.AppendLine(valid ? "Success!" : "Not a match.");
                }
                return valid;
            }));
        }