Ejemplo n.º 1
0
        public string GetSigningCertificateFingerprint(HashAlgorithmName algorithm)
        {
            if (!Enum.IsDefined(typeof(HashAlgorithmName), algorithm))
            {
                throw new ArgumentException(
                          string.Format(
                              CultureInfo.CurrentCulture,
                              Strings.UnrecognizedEnumValue,
                              algorithm),
                          nameof(algorithm));
            }

            var certificate = SignerInfo.Certificate;

            if (certificate == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Strings.Verify_ErrorNoCertificate, FriendlyName));
            }

            if (_signingCertificateFingerprintLookup == null)
            {
                _signingCertificateFingerprintLookup = new Dictionary <HashAlgorithmName, string>();
            }

            if (_signingCertificateFingerprintLookup.TryGetValue(algorithm, out var fingerprint))
            {
                return(fingerprint);
            }

            fingerprint = CertificateUtility.GetHashString(certificate, algorithm);

            _signingCertificateFingerprintLookup.Add(algorithm, fingerprint);

            return(fingerprint);
        }
Ejemplo n.º 2
0
        private static string GetCertificateFingerprint(
            Signature signature,
            HashAlgorithmName fingerprintAlgorithm,
            IDictionary <HashAlgorithmName, string> CertificateFingerprintLookUp)
        {
            if (!CertificateFingerprintLookUp.TryGetValue(fingerprintAlgorithm, out var fingerprintString))
            {
                fingerprintString = CertificateUtility.GetHashString(signature.SignerInfo.Certificate, fingerprintAlgorithm);
                CertificateFingerprintLookUp[fingerprintAlgorithm] = fingerprintString;
            }

            return(fingerprintString);
        }