public Task <bool> VerifyAsync(byte[] digest, byte[] signature, string algorithm, CancellationToken token = default(CancellationToken))
        {
            if (_csp == null)
            {
                throw new ObjectDisposedException(string.Format("RsaKey {0} is disposed", Kid));
            }

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

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

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

            AsymmetricSignatureAlgorithm algo      = AlgorithmResolver.Default[algorithm] as AsymmetricSignatureAlgorithm;
            ISignatureTransform          transform = algo != null?algo.CreateSignatureTransform(_csp) : null;

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

            try
            {
                var result = transform.Verify(digest, signature);

                return(Task.FromResult(result));
            }
            catch (Exception ex)
            {
                return(TaskException.FromException <bool>(ex));
            }
        }
        public 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");
            }

            // TODO: Not available via the RSA class
            //if ( _csp.PublicOnly )
            //    throw new NotSupportedException( "Sign is not supported because no private key is available" );

            AsymmetricSignatureAlgorithm algo      = AlgorithmResolver.Default[algorithm] as AsymmetricSignatureAlgorithm;
            ISignatureTransform          transform = algo != null?algo.CreateSignatureTransform(_csp) : null;

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

            try
            {
                var result = new Tuple <byte[], string>(transform.Sign(digest), algorithm);

                return(Task.FromResult(result));
            }
            catch (Exception ex)
            {
                return(TaskException.FromException <Tuple <byte[], string> >(ex));
            }
        }