public AsymmetricAlgorithm Create(ICryptoKey publicKey)
        {
            this.cryptoServiceProvider = new RSACryptoServiceProvider { PersistKeyInCsp = false };
            this.cryptoServiceProvider.FromXmlString(publicKey.Contents);

            return this.cryptoServiceProvider;
        }
        public AsymmetricAlgorithm Create(ICryptoKey publicKey)
        {
            this.cryptoServiceProvider = new RSACryptoServiceProvider {
                PersistKeyInCsp = false
            };
            this.cryptoServiceProvider.FromXmlString(publicKey.Contents);

            return(this.cryptoServiceProvider);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Validates the supplied client license against the private key and the set of validation rules. Violations are exposed via exceptions or aggregate exceptions.
        /// </summary>
        /// <param name="clientLicense">License to validate</param>
        /// <param name="publicKey">Public Key to validate the license with</param>
        /// <param name="validationRules">List of validation rules to examine</param>
        /// <exception cref="InvalidLicenseException">Indicates that the license is invalid / corrupt / empty.</exception>
        /// <exception cref="LicenseViolationException">Indicates that a license validation rule has been violated.</exception>
        /// <exception cref="AggregateException">Indicates that one or more license validation rules have been violated.</exception>
        public void Validate(IClientLicense clientLicense, ICryptoKey publicKey, IEnumerable <ILicenseValidationRule> validationRules, string elementKey = null)
        {
            if (!LicenseSignatureValidator.ValidateSignature(clientLicense, publicKey))
            {
                throw new InvalidLicenseException(clientLicense);
            }

            this.LicenseCriteria = this.licenseCriteriaParser.Parse(clientLicense, elementKey);

            validationRules.ForEachFailEnd(x => x.Validate(this.LicenseCriteria));
        }
        /// <summary>
        /// Validates the supplied client license against the private key and the set of validation rules. Violations are exposed via exceptions or aggregate exceptions.
        /// </summary>
        /// <param name="clientLicense">License to validate</param>
        /// <param name="publicKey">Public Key to validate the license with</param>
        /// <param name="validationRules">List of validation rules to examine</param>
        /// <exception cref="InvalidLicenseException">Indicates that the license is invalid / corrupt / empty.</exception>
        /// <exception cref="LicenseViolationException">Indicates that a license validation rule has been violated.</exception>
        /// <exception cref="AggregateException">Indicates that one or more license validation rules have been violated.</exception>
        public void Validate(IClientLicense clientLicense, ICryptoKey publicKey, IEnumerable<ILicenseValidationRule> validationRules)
        {
            if (!LicenseSignatureValidator.ValidateSignature(clientLicense, publicKey))
            {
                throw new InvalidLicenseException(clientLicense);
            }

            this.LicenseCriteria = this.licenseCriteriaParser.Parse(clientLicense);

            validationRules.ForEachFailEnd(x => x.Validate(this.LicenseCriteria));
        }
        public static bool ValidateSignature(IClientLicense license, ICryptoKey publicKey)
        {
            var namespaceManager = new XmlNamespaceManager(license.Content.NameTable);
            namespaceManager.AddNamespace("sig", "http://www.w3.org/2000/09/xmldsig#");

            var signature = (XmlElement)license.Content.SelectSingleNode("//sig:Signature", namespaceManager);

            if (signature == null)
            {
                return false;
            }

            var signedXml = new SignedXml(license.Content);
            signedXml.LoadXml(signature);

            using (var publicKeyProvider = new RsaPublicKeyProvider())
            {
                return signedXml.CheckSignature(publicKeyProvider.Create(publicKey));
            }
        }
        public static bool ValidateSignature(IClientLicense license, ICryptoKey publicKey)
        {
            var namespaceManager = new XmlNamespaceManager(license.Content.NameTable);

            namespaceManager.AddNamespace("sig", "http://www.w3.org/2000/09/xmldsig#");

            var signature = (XmlElement)license.Content.SelectSingleNode("//sig:Signature", namespaceManager);

            if (signature == null)
            {
                return(false);
            }

            var signedXml = new SignedXml(license.Content);

            signedXml.LoadXml(signature);

            using (var publicKeyProvider = new RsaPublicKeyProvider())
            {
                return(signedXml.CheckSignature(publicKeyProvider.Create(publicKey)));
            }
        }
Exemplo n.º 7
0
 public static string KeyToString(ICryptoKey key)
 {
     return($"{key.Exponent}/{key.Modulus}");
 }
Exemplo n.º 8
0
 public bool IsValid(ICryptoKey key)
 {
     return(IsValid(key.KeyCodes));
 }
Exemplo n.º 9
0
 public CipherException(string plainText, ICryptoKey key)
 {
     _plainText = plainText;
     _key       = key;
 }