示例#1
1
        /// <summary>
        /// Determines whether the <see cref="ILicense.Signature"/> property verifies for the specified key.
        /// </summary>
        /// <param name="publicKey">The public key in xml string format to verify the <see cref="ILicense.Signature"/>.</param>
        /// <returns>true if the <see cref="ILicense.Signature"/> verifies; otherwise false.</returns>
        public bool VerifySignature(string publicKey)
        {
            var signTag = Element("Signature");
            
            if (signTag == null)
                return false;

            try
            {
                signTag.Remove();

                using (var e = new Security.Cryptography.ElGamal.ElGamalManaged())
                {
                    e.FromXmlString(publicKey);
                    return e.VerifySignature(Encoding.UTF8.GetBytes(ToString(SaveOptions.DisableFormatting)),
                                             Convert.FromBase64String(signTag.Value));
                }
            }
            finally
            {
                Add(signTag);
            }
        }
示例#2
0
        /// <summary>
        /// Compute a signature and sign this <see cref="ILicense"/> with the provided key.
        /// </summary>
        /// <param name="privateKey">The private key in xml string format to compute the signature.</param>
        public void Sign(string privateKey)
        {
            var signTag = Element("Signature") ?? new XElement("Signature");

            try
            {
                if (signTag.Parent != null)
                    signTag.Remove();

                using (var e = new Security.Cryptography.ElGamal.ElGamalManaged())
                {
                    e.FromXmlString(privateKey);
                    var signature = e.Sign(Encoding.UTF8.GetBytes(ToString(SaveOptions.DisableFormatting)));
                    signTag.Value = Convert.ToBase64String(signature);
                }
            }
            finally
            {
                Add(signTag);
            }
        }