Exemple #1
0
        /// <summary>
        ///     Computes the signature of a hash that was produced by the hash algorithm specified by "hashAlgorithm."
        /// </summary>
        public override byte[] SignHash(byte[] hash)
        {
            if (hash == null)
            {
                throw new ArgumentNullException("hash");
            }

            int estimatedSize;

            switch (KeySize)
            {
            case 256: estimatedSize = 64; break;

            case 384: estimatedSize = 96; break;

            case 521: estimatedSize = 132; break;

            default:
                // If we got here, the range of legal key sizes for ECDsaCng was expanded and someone didn't update this switch.
                // Since it isn't a fatal error to miscalculate the estimatedSize, don't throw an exception. Just truck along.
                estimatedSize = KeySize / 4;
                break;
            }

            unsafe
            {
                byte[] signature = CngAsymmetricAlgorithmCore.SignHash(Key, hash, AsymmetricPaddingMode.None, null, estimatedSize);
                return(signature);
            }
        }
Exemple #2
0
        /// <summary>
        ///     Computes the signature of a hash that was produced by the hash algorithm specified by "hashAlgorithm."
        /// </summary>
        public override byte[] SignHash(byte[] hash, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
        {
            if (hash == null)
            {
                throw new ArgumentNullException("hash");
            }

            unsafe
            {
                byte[] signature = null;
                SignOrVerify(padding, hashAlgorithm, hash,
                             delegate(AsymmetricPaddingMode paddingMode, void *pPaddingInfo)
                {
                    int estimatedSize = KeySize / 8;
                    signature         = CngAsymmetricAlgorithmCore.SignHash(Key, hash, paddingMode, pPaddingInfo, estimatedSize);
                }
                             );
                return(signature);
            }
        }