Exemple #1
0
        public MFTestResults AesTest_EncryptUpdate()
        {
            MFTestResults res;

            try
            {
                using (AesCryptoServiceProvider csp = new AesCryptoServiceProvider())
                {
                    res = SymmetricTestHelper.Test_EncryptUpdate(csp);
                }

                if (res == MFTestResults.Pass && m_isEmulator)
                {
                    using (AesCryptoServiceProvider csp = new AesCryptoServiceProvider("Emulator_Crypto"))
                    {
                        res = SymmetricTestHelper.Test_EncryptUpdate(csp);
                    }
                }
            }
            catch
            {
                res = MFTestResults.Fail;
            }

            return(res);
        }
Exemple #2
0
        bool SessionTest_CloseWithCreateKeyObjects_internal(string svcProvider)
        {
            bool res = true;

            CryptoKey key;

            using (Session sess = new Session(svcProvider, MechanismType.AES_CBC))
            {
                AesCryptoServiceProvider aes = new AesCryptoServiceProvider(sess);

                aes.GenerateKey();

                key = aes.Key;

                SymmetricTestHelper.Test_EncryptUpdate(aes);
            }

            try
            {
                using (AesCryptoServiceProvider aes = new AesCryptoServiceProvider(svcProvider))
                {
                    aes.Key = key;

                    SymmetricTestHelper.Test_EncryptUpdate(aes);
                }

                res = false;
            }
            catch (Exception)
            {
            }

            return(res);
        }
Exemple #3
0
        bool SessionTest_CloseWithOpenKeyObjects_internal(string svcProvider)
        {
            bool res = true;

            CryptoKey key;

            using (Session sess = new Session(svcProvider, MechanismType.AES_CBC))
            {
                using (AesCryptoServiceProvider aes = new AesCryptoServiceProvider(sess))
                {
                    key = CryptoKey.LoadKey(sess, m_key);

                    aes.Key = key;

                    SymmetricTestHelper.Test_EncryptUpdate(aes);
                }

                using (AesCryptoServiceProvider aes2 = new AesCryptoServiceProvider(sess))
                {
                    key = CryptoKey.LoadKey(sess, m_key);

                    aes2.Key = key;

                    SymmetricTestHelper.Test_EncryptUpdate(aes2);
                }
            }

            try
            {
                // new session should fail, key should be disposed
                using (AesCryptoServiceProvider aes = new AesCryptoServiceProvider(svcProvider))
                {
                    aes.Key = key;

                    SymmetricTestHelper.Test_EncryptUpdate(aes);
                }

                res = false;
            }
            catch (Exception)
            {
            }

            return(res);
        }