Beispiel #1
0
        /// <summary>
        /// Compares two KeyInfo objects.
        /// </summary>
        public override bool Equals(object obj)
        {
            KeyInfo other = obj as KeyInfo;

            if (other == null)
            {
                return(false);
            }
            else if (string.Compare(KeyName, other.KeyName, StringComparison.OrdinalIgnoreCase) != 0 ||
                     string.Compare(RetrievalMethodUri, other.RetrievalMethodUri, StringComparison.OrdinalIgnoreCase) != 0 ||
                     (RSAKeyValue != null && !RSAKeyValue.Equals(other.RSAKeyValue) ||
                      !new HashSet <X509Data>(X509Data).SetEquals(other.X509Data)))
            {
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Initializes an instance of <see cref="KeyInfo"/>.
        /// </summary>
        /// <param name="key">the <see cref="SecurityKey"/>to populate the <see cref="KeyInfo"/>.</param>
        public KeyInfo(SecurityKey key)
        {
            if (key is X509SecurityKey x509Key)
            {
                var data = new X509Data();
                data.Certificates.Add(Convert.ToBase64String(x509Key.Certificate.RawData));
                X509Data.Add(data);
            }
            else if (key is RsaSecurityKey rsaKey)
            {
                var rsaParameters = rsaKey.Parameters;

                // Obtain parameters from the RSA if the rsaKey does not contain a valid value for RSAParameters
                if (rsaKey.Parameters.Equals(default(RSAParameters)))
                {
                    rsaParameters = rsaKey.Rsa.ExportParameters(false);
                }

                RSAKeyValue = new RSAKeyValue(Convert.ToBase64String(rsaParameters.Modulus), Convert.ToBase64String(rsaParameters.Exponent));
            }
        }