/// <summary>
        /// Computes the signature for the specified hash value by encrypting it with the private key.
        /// </summary>
        /// <param name="rgbHash">The hash value of the data to be signed.</param>
        /// <param name="hashAlgorithm">The hash algorithm used to create the hash value of the data.</param>
        /// <returns>The DSA signature for the specified hash value.</returns>
        public byte[] SignHash(byte[] rgbHash, MechanismType hashAlgorithm) 
        {
            if (rgbHash == null)
                throw new ArgumentNullException();
            if (PublicOnly || rgbHash.Length == 0)
                throw new CryptographicException();

            byte[] sig = null;

            m_signatureMech.Parameter = Utility.ConvertToBytes((int)(hashAlgorithm | MechanismType.SIGN_NO_NODIGEST_FLAG));

            using (CryptokiSign sign = new CryptokiSign(m_session, m_signatureMech, KeyPair))
            {
                sig = sign.Sign(rgbHash, 0, rgbHash.Length);
            }

            return sig;
        }
        /// <summary>
        /// Computes the hash value of a subset of the specified byte array using the specified hash algorithm, and signs the resulting hash value.
        /// </summary>
        /// <param name="buffer">The input data for which to compute the hash.</param>
        /// <param name="offset">The offset into the array from which to begin using data.</param>
        /// <param name="count">The number of bytes in the array to use as data.</param>
        /// <param name="hash">The hash algorithm to use to create the hash value.</param>
        /// <returns>The RSA signature for the specified data.</returns>
        public byte[] SignData(byte[] buffer, int offset, int count, HashAlgorithm hash)
        {
            byte[] retVal;

            if (hash != null)
            {
                //return SignHash(hash.ComputeHash(buffer, offset, count));
                m_signHashMech.Parameter = Utility.ConvertToBytes((int)hash.HashType);
            }
            else
            {
                m_signHashMech.Parameter = Utility.ConvertToBytes((int)m_hashMech);
            }

            using (CryptokiSign sig = new CryptokiSign(m_session, m_signHashMech, KeyPair))
            {
                retVal = sig.Sign(buffer, offset, count);
            }

            return retVal;
        }
        /// <summary>
        /// Computes the hash value of the specified byte array and signs the resulting hash value.
        /// </summary>
        /// <param name="buffer">The input data for which to compute the hash.</param>
        /// <param name="offset">The offset index into the buffer</param>
        /// <param name="count">The number of bytes from the offset to process for the hash operation.</param>
        /// <returns>The DSA signature for the specified data.</returns>
        public byte[] SignData(byte[] buffer, int offset, int count) 
        {
            byte[] retVal;

            if (buffer == null)
            {
                throw new ArgumentNullException();
            }
            if (offset < 0 || offset > buffer.Length)
            {
                throw new ArgumentOutOfRangeException();
            }
            if (count < 0 || count > buffer.Length - offset)
            {
                throw new ArgumentOutOfRangeException();
            }

            m_signatureMech.Parameter = Utility.ConvertToBytes((int)m_hashAlgorithm);

            using (CryptokiSign sig = new CryptokiSign(m_session, m_signatureMech, KeyPair))
            {
                retVal = sig.Sign(buffer, offset, count);
            }

            return retVal;
        }
        /// <summary>
        /// Computes the hash value of the specified input stream using the specified hash algorithm, and signs the resulting hash value.
        /// </summary>
        /// <param name="inputStream">The input data for which to compute the hash.</param>
        /// <param name="hash">The hash algorithm to use to create the hash value.</param>
        /// <returns>The RSA signature for the specified data.</returns>
        public byte[] SignData(Stream inputStream, HashAlgorithm hash) 
        {
            byte[] retVal;
            byte[] data;

            if (hash != null)
            {
                m_signHashMech.Parameter = Utility.ConvertToBytes((int)hash.HashType);
            }
            else
            {
                m_signHashMech.Parameter = Utility.ConvertToBytes((int)m_hashMech);
            }

            // TODO: look at breaking this up for stream so that it i only reads x amount at a time
            data = new byte[(int)inputStream.Length];
            
            int len = inputStream.Read(data, 0, data.Length);

            using (CryptokiSign sig = new CryptokiSign(m_session, m_signHashMech, KeyPair))
            {
                retVal = sig.Sign(data, 0, len);
            }

            return retVal;
        }