示例#1
0
        public async Task <Tuple <byte[], string> > SignAsync(byte[] digest, string algorithm, CancellationToken token = default(CancellationToken))
        {
            if (_csp == null)
            {
                throw new ObjectDisposedException(string.Format("RsaKey {0} is disposed", Kid));
            }

            if (algorithm == null)
            {
                algorithm = DefaultSignatureAlgorithm;
            }

            if (digest == null)
            {
                throw new ArgumentNullException("digest");
            }

            if (_csp.PublicOnly)
            {
                throw new NotSupportedException("Sign is not supported because no private key is available");
            }

            AsymmetricSignatureAlgorithm algo = AlgorithmResolver.Default[algorithm] as AsymmetricSignatureAlgorithm;

            if (algo == null)
            {
                throw new NotSupportedException("algorithm is not supported");
            }

            return(new Tuple <byte[], string>(algo.SignHash(_csp, digest), algorithm));
        }
        public async Task <Tuple <byte[], string> > SignAsync(byte[] digest, string algorithm = null, CancellationToken token = default(CancellationToken))
        {
            if (_certificate == null)
            {
                throw new ObjectDisposedException(string.Format("Certificate {0} is disposed", Kid));
            }

            if (!_certificate.HasPrivateKey)
            {
                throw new NotSupportedException("Certificate does not have a private key");
            }

            if (digest == null)
            {
                throw new ArgumentNullException("digest");
            }

            if (algorithm == null)
            {
                algorithm = DefaultSignatureAlgorithm;
            }

            AsymmetricSignatureAlgorithm algo = AlgorithmResolver.Default[algorithm] as AsymmetricSignatureAlgorithm;

            if (algo == null)
            {
                throw new NotSupportedException("algorithm is not supported");
            }

            return(new Tuple <byte[], string>(algo.SignHash(_certificate.PrivateKey, digest), algorithm));
        }