Esempio n. 1
0
        public async Task <Tuple <byte[], string> > SignAsync(string hex)
        {
            this.EnsureUsable();
            if (this.NotAfter < DateTime.UtcNow)
            {
                throw new EncryptionException($"Operation is not allowed on expired key; Key '{this.Actor}/{this.KeyId}'.");
            }
            var crypto    = this.GetRSACryptoServiceProvider();
            var signer    = new Signing.Signer(crypto);
            var algorithm = BasicHasher.GetNormalAlgorithm(hex);

            return(await Task.FromResult(signer.SignHash(hex, algorithm)));
        }
        /// <summary>
        /// Signs a byte array by creating an appropriate hash.
        /// </summary>
        /// <param name="digest">Any data to sign.</param>
        /// <param name="algorithm">MD5 or SHA1</param>
        /// <param name="token"></param>
        /// <returns>The signature for the digest as a byte array and string based hash code.</returns>
        public async Task<Tuple<byte[], string>> SignAsync(byte[] digest, string algorithm, CancellationToken token)
        {
            this.EnsureUsable();

            if (digest == null || !digest.Any())
            {
                throw new ArgumentException("digest");
            }
            if (algorithm == null)
            {
                throw new ArgumentNullException("algorithm");
            }
            var crypto = this.GetRSACryptoServiceProvider();
            var signer = new Signing.Signer(crypto);
            //var hash = BasicHasher.GetHash(digest, algorithm);
            return await Task.FromResult(signer.SignHash(digest, algorithm));
        }
Esempio n. 3
0
        /// <summary>
        /// Signs a byte array by creating an appropriate hash.
        /// </summary>
        /// <param name="digest">Any data to sign.</param>
        /// <param name="algorithm">MD5 or SHA1</param>
        /// <param name="token"></param>
        /// <returns>The signature for the digest as a byte array and string based hash code.</returns>
        public async Task <Tuple <byte[], string> > SignAsync(byte[] digest, string algorithm, CancellationToken token)
        {
            this.EnsureUsable();
            if (this.NotAfter < DateTime.UtcNow)
            {
                throw new EncryptionException($"Operation is not allowed on expired key; Key '{this.Actor}/{this.KeyId}'.");
            }

            if (digest == null || !digest.Any())
            {
                throw new ArgumentException("digest");
            }
            if (algorithm == null)
            {
                throw new ArgumentNullException("algorithm");
            }
            var crypto = this.GetRSACryptoServiceProvider();
            var signer = new Signing.Signer(crypto);

            //var hash = BasicHasher.GetHash(digest, algorithm);
            return(await Task.FromResult(signer.SignHash(digest, algorithm)));
        }
 public async Task<Tuple<byte[], string>> SignAsync(string hex)
 {
     this.EnsureUsable();
     var crypto = this.GetRSACryptoServiceProvider();
     var signer = new Signing.Signer(crypto);
     var algorithm = BasicHasher.GetNormalAlgorithm(hex);
     return await Task.FromResult(signer.SignHash(hex, algorithm));
 }