Exemplo n.º 1
0
        /// <summary>
        /// Generates a signature and signs the <see cref="License"/> with the provided key.
        /// </summary>
        /// <param name="privateKey">The private key.</param>
        /// <returns>A signed <see cref="License"/>.</returns>
        public License Sign(byte[] privateKey)
        {
            Signature = null;
            var j    = JObject.FromObject(this);
            var json = Encoding.UTF8.GetBytes(j.ToString(Formatting.None));

            var signer = new ECC.Signer();

            Signature = signer.Sign(json, privateKey ?? signer.PrivateKey);
            return(this);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks if the <see cref="License.Signature"/> property can be verified using the provided public key.
        /// </summary>
        /// <param name="publicKey">The public key for this product.</param>
        /// <returns>true if the <see cref="License.Signature"/> is correct; otherwise false.</returns>
        public bool VerifySignature(byte[] publicKey)
        {
            var sig = Signature;

            Signature = null;

            try {
                var j    = JObject.FromObject(this);
                var json = Encoding.UTF8.GetBytes(j.ToString(Formatting.None));

                var signer = new ECC.Signer();
                return(signer.Verify(json, sig, publicKey));
            }
            finally {
                Signature = sig;
            }
        }