Esempio n. 1
0
        /// <summary>
        /// Sign the data with the RSA CSP.
        /// </summary>
        /// <param name="data">The data to sign.</param>
        /// <param name="cspParameters">The CSP parameters.</param>
        /// <param name="hashcode">The hash code to use.</param>
        /// <returns>The signature.</returns>
        /// <remarks>
        /// Create a new CspParameters object that identifies a
        /// Smart Card CryptoGraphic Provider.
        /// The 1st parameter comes from HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\Defaults\Provider Types.
        /// The 2nd parameter comes from HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\Defaults\Provider.
        /// </remarks>
        public byte[] Sign(byte[] data, CspParameters cspParameters, HashcodeType hashcode = HashcodeType.SHA512)
        {
            // Initialize an RSACryptoServiceProvider object using
            // the CspParameters object.
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cspParameters);

            // Sign the data using the Smart Card CryptoGraphic Provider.
            byte[] sig = rsa.SignData(data, hashcode.ToString());
            return(sig);
        }
Esempio n. 2
0
        /// <summary>
        /// Verify the data with the RSA CSP.
        /// </summary>
        /// <param name="data">The data that was signed.</param>
        /// <param name="signature">The signature of the original data.</param>
        /// <param name="cspParameters">The CSP parameters.</param>
        /// <param name="hashcode">The hash code to use.</param>
        /// <returns>True if the data is valid; else false.</returns>
        /// <remarks>
        /// Create a new CspParameters object that identifies a
        /// Smart Card CryptoGraphic Provider.
        /// The 1st parameter comes from HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\Defaults\Provider Types.
        /// The 2nd parameter comes from HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\Defaults\Provider.
        /// </remarks>
        public bool Verify(byte[] data, byte[] signature, CspParameters cspParameters, HashcodeType hashcode = HashcodeType.SHA512)
        {
            // Initialize an RSACryptoServiceProvider object using
            // the CspParameters object.
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cspParameters);

            // Verify the data using the Smart Card CryptoGraphic Provider.
            bool verified = rsa.VerifyData(data, hashcode.ToString(), signature);

            return(verified);
        }