Пример #1
0
        public MFTestResults DsaTest_ImportRsaKeyAndUseWithDsaShouldFail()
        {
            bool testResult = false;

            try
            {
                using (Session session = new Session("", MechanismType.DSA))
                    using (CryptoKey obj = CryptokiObject.CreateObject(session, m_privateRsaKey) as CryptoKey)
                    {
                        string dataToSign = "This is a simple message to be encrypted";

                        byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(dataToSign);

                        using (DSACryptoServiceProvider dsa = new DSACryptoServiceProvider(obj))
                        {
                            byte[] signature = dsa.SignData(data);

                            dsa.VerifyData(data, signature);
                        }
                    }
            }
            catch (ArgumentException)
            {
                testResult = true;
            }
            catch
            {
                testResult = false;
            }

            return(testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
Пример #2
0
        /// <summary>
        /// Creates a CryptoKey in the specfied session context with the specified key attribute template.
        /// </summary>
        /// <param name="session">The Cryptoki session context.</param>
        /// <param name="keyTemplate">The Cryptoki attribute template that specifies key properties.</param>
        /// <returns></returns>
        public static CryptoKey LoadKey(Session session, CryptokiAttribute[] keyTemplate)
        {
            CryptoKey key = CryptokiObject.CreateObject(session, keyTemplate) as CryptoKey;

            key.m_keyType = KeyType.INVALID;

            return(key);
        }