当前位置: 首页>>代码示例>>C#>>正文


C# Cryptoki.Session类代码示例

本文整理汇总了C#中Microsoft.SPOT.Cryptoki.Session的典型用法代码示例。如果您正苦于以下问题:C# Session类的具体用法?C# Session怎么用?C# Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Session类属于Microsoft.SPOT.Cryptoki命名空间,在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RNG2_Test

        public MFTestResults RNG2_Test()
        {
            bool bRes = true;

            try
            {
                using (Session sess = new Session("", MechanismType.RSA_PKCS))
                {
                    bRes &= Test(sess);
                }

                if (m_isEmulator)
                {
                    using (Session sess = new Session("Emulator_Crypto", MechanismType.RSA_PKCS))
                    {
                        bRes &= Test(sess);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Exception("", e);
                bRes = false;
            }
            return bRes ? MFTestResults.Pass : MFTestResults.Fail;
        }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:26,代码来源:Rng2.cs

示例2: CryptokiSign

 /// <summary>
 /// Creates a Cryptoki signature object with the specified session context, algorithm and key.
 /// </summary>
 /// <param name="session">The Cryptoki session context.</param>
 /// <param name="mechanism">The signature algorithm and parameters.</param>
 /// <param name="key">The key used to sign the input data.</param>
 public CryptokiSign(Session session, Mechanism mechanism, CryptoKey key) : 
     base(session, false)
 {
     m_signatureLength = (key.Size + 7) / 8;
     m_mech = mechanism;
     m_key  = key;
 }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:13,代码来源:Signing.cs

示例3: HashAlgorithm

 /// <summary>
 /// Initializes a new instance of the HashAlgorithm class.
 /// </summary>
 /// <param name="session">The Cryptoki session context the hash algorithm will execute in.</param>
 /// <param name="mechanism">The hash algorithm type</param>
 public HashAlgorithm(HashAlgorithmType hashAlgorithm, Session session)
     : base(session, false)
 {
     m_mechanism = new Mechanism((MechanismType)hashAlgorithm);
     m_hashSize = -1;
     Initialize();
 }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:12,代码来源:HashAlgorithm.cs

示例4: SessionTest_CloseWithCreateKeyObjects_internal

        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;
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:34,代码来源:SessionTests.cs

示例5: testRng

        bool testRng(Session session)
        {
            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(session);

            byte[] data1 = new byte[1024];
            byte[] data2 = new byte[1024];
            byte[] data3 = new byte[1024];

            rng.GetBytes(data1);
            rng.GetBytes(data2);
            rng.Dispose();

            rng = new RNGCryptoServiceProvider(session);

            rng.GetBytes(data3);
            rng.Dispose();

            int same = 0;
            for (int i = 0; i < data1.Length; i++)
            {
                if (data1[i] == data2[i] || data1[i] == data3[i] || data2[i] == data3[i]) same++;
            }

            return same < 32; // ~3% matching elements
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:25,代码来源:RNGTest.cs

示例6: X509CertificateLoadCertsFromBlob_Test

        public MFTestResults X509CertificateLoadCertsFromBlob_Test()
        {
            bool bRet = true;
            X509CertificateLoadCertsFromBlob x509;

            //TestLibrary.TestFramework.BeginTestCase("X509CertificateLoadCertsFromBlob");

            x509 = new X509CertificateLoadCertsFromBlob();

            c_BYTES = Properties.Resources.GetBytes(Properties.Resources.BinaryResources.cacert);

            using(Session session = new Session("", MechanismType.RSA_PKCS))
            {
                bRet &= x509.RunTests(session);
            }
            if(m_isEmulator)
            {
                using (Session session = new Session("Emulator_Crypto", MechanismType.RSA_PKCS))
                {
                    bRet &= x509.RunTests(session);
                }
            }

            return bRet ? MFTestResults.Pass : MFTestResults.Fail;
        }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:25,代码来源:X509CertificateLoadCertFromBlob.cs

示例7: DsaTest_ImportDsaKey

        public MFTestResults DsaTest_ImportDsaKey()
        {
            MFTestResults res;

            try
            {
                using (Session session = new Session("", MechanismType.DSA))
                {
                    res = Test_ImportKey(session);
                }

                if (res == MFTestResults.Pass && m_isEmulator)
                {
                    using (Session session = new Session("Emulator_Crypto", MechanismType.DSA))
                    {
                        res = Test_ImportKey(session);
                    }
                }
            }
            catch
            {
                res = MFTestResults.Fail;
            }

            return res;
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:26,代码来源:DsaTests.cs

示例8: Zeros_Test

        public MFTestResults Zeros_Test()
        {
            bool bRes = true;

            try
            {
                Zeros tester = new Zeros();

                using (Session sess = new Session("", MechanismType.AES_ECB))
                {
                    bRes &= tester.RunTests(sess, PaddingMode.Zeros);
                }

                if (m_isEmulator)
                {
                    using (Session sess = new Session("Emulator_Crypto", MechanismType.AES_ECB))
                    {
                        bRes &= tester.RunTests(sess, PaddingMode.Zeros);
                    }
                }
            }
            catch (NotSupportedException)
            {
                return MFTestResults.Skip;
            }
            catch (Exception e)
            {
                Log.Exception("", e);
                bRes = false;
            }
            return bRes ? MFTestResults.Pass : MFTestResults.Fail;
        }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:32,代码来源:Zeros.cs

示例9: SymmetricAlgorithm

 /// <summary>
 /// Initializes a new instance of the SymmetricAlgorithm class.
 /// </summary>
 /// <param name="session">The cryptoki session context for which the symmectric algorithm will execute.</param>
 /// <param name="ownsSession">true if the session should be closed by this base class, false otherwise.</param>
 protected SymmetricAlgorithm(Session session, bool ownsSession)
     : base(session, ownsSession)
 {
     // Default to cipher block chaining (CipherMode.CBC) and
     // PKCS-style padding (pad n bytes with value n)
     ModeValue = CipherMode.CBC;
     PaddingValue  = PaddingMode.PKCS7;
 }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:13,代码来源:SymmetricAlgorithm.cs

示例10: CreateObject

        /// <summary>
        /// Creates a object in the given Cryptoki session context with specified object atrributes.
        /// </summary>
        /// <param name="session">The Cryptoki session context.</param>
        /// <param name="template">The object attribute template.</param>
        /// <returns>The cryptoki object created.</returns>
        public static CryptokiObject CreateObject(Session session, CryptokiAttribute[] template)
        {
            CryptokiObject ret = CreateObjectInternal(session, template);

            session.AddSessionObject(ret);

            return ret;
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:14,代码来源:Object.cs

示例11: LoadKey

        /// <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;
        }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:14,代码来源:Key.cs

示例12: Test

        static Boolean Test(Session session)
        {
            Boolean bRes = true;
            Byte[] abData1 = { (Byte)'a', (Byte)'b', (Byte)'c' };
            Byte[] abDigest1 = {0xdd, 0xaf, 0x35, 0xa1, 0x93, 0x61, 0x7a, 0xba,
        					0xcc, 0x41, 0x73, 0x49, 0xae, 0x20, 0x41, 0x31,
        					0x12, 0xe6, 0xfa, 0x4e, 0x89, 0xa9, 0x7e, 0xa2,
        					0x0a, 0x9e, 0xee, 0xe6, 0x4b, 0x55, 0xd3, 0x9a,
        					0x21, 0x92, 0x99, 0x2a, 0x27, 0x4f, 0xc1, 0xa8,
        					0x36, 0xba, 0x3c, 0x23, 0xa3, 0xfe, 0xeb, 0xbd,
        					0x45, 0x4d, 0x44, 0x23, 0x64, 0x3c, 0xe8, 0x0e,
        					0x2a, 0x9a, 0xc9, 0x4f, 0xa5, 0x4c, 0xa4, 0x9f};
            String sData2 = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
            Byte[] abData2 = new Byte[sData2.Length];
            for (int i = 0; i < sData2.Length; i++) abData2[i] = (Byte)sData2[i];
            Byte[] abDigest2 = {0x8e, 0x95, 0x9b, 0x75, 0xda, 0xe3, 0x13, 0xda,
        					0x8c, 0xf4, 0xf7, 0x28, 0x14, 0xfc, 0x14, 0x3f,
        					0x8f, 0x77, 0x79, 0xc6, 0xeb, 0x9f, 0x7f, 0xa1,
        					0x72, 0x99, 0xae, 0xad, 0xb6, 0x88, 0x90, 0x18,
        					0x50, 0x1d, 0x28, 0x9e, 0x49, 0x00, 0xf7, 0xe4,
        					0x33, 0x1b, 0x99, 0xde, 0xc4, 0xb5, 0x43, 0x3a,
        					0xc7, 0xd3, 0x29, 0xee, 0xb6, 0xdd, 0x26, 0x54,
        					0x5e, 0x96, 0xe5, 0x5b, 0x87, 0x4b, 0xe9, 0x09};

            Log.Comment("Testing SHA1 hash...");
            HashAlgorithm sha1 = new HashAlgorithm(HashAlgorithmType.SHA512, session);
            HashAlgorithm sha2 = new HashAlgorithm(HashAlgorithmType.SHA512, session);
            sha1.ComputeHash(abData1);
            sha2.ComputeHash(abData2);
            Log.Comment("The computed hash #1 is : ");
            PrintByteArray(sha1.Hash);
            Log.Comment("The correct hash #1 is : ");
            PrintByteArray(abDigest1);
            if (Compare(sha1.Hash, abDigest1))
            {
                Log.Comment("CORRECT");
            }
            else
            {
                Log.Comment("INCORRECT");
                bRes = false;
            }
            Log.Comment("The computed hash #2 is : ");
            PrintByteArray(sha2.Hash);
            Log.Comment("The correct hash #2 is : ");
            PrintByteArray(abDigest2);
            if (Compare(sha2.Hash, abDigest2))
            {
                Log.Comment("CORRECT");
            }
            else
            {
                Log.Comment("INCORRECT");
                bRes = false;
            }

            return bRes;
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:58,代码来源:Hash_SHA512known.cs

示例13: Encryptor

        /// <summary>
        /// Creates the encryptor object with the specified session context, decryption algorithm, key, and input/output block sizes
        /// </summary>
        /// <param name="session">The Cryptoki session context.</param>
        /// <param name="mechanism">The encryption algorithm and paramters.</param>
        /// <param name="key">The key that will be used to perform the encryption.</param>
        /// <param name="inputBlockSize">The input block size, in bits.</param>
        /// <param name="outputBlockSize">The output block size, in bits.</param>
        public Encryptor(Session session, Mechanism mechanism, CryptoKey key, int inputBlockSize, int outputBlockSize) :
            base(session, false)
        {
            m_inputBlockSize  = (inputBlockSize + 7) / 8;
            m_outputBlockSize = (outputBlockSize+ 7) / 8;

            m_mech = mechanism;
            m_key  = key;
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:17,代码来源:Encrypt.cs

示例14: Test

        static Boolean Test(Session session)
        {
            Boolean bRes = true;
            Byte[] abKey1 = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
            Byte[] abData1 = (new System.Text.UTF8Encoding()).GetBytes("Hi There");
            Byte[] abDigest1 = { 0xb6, 0x17, 0x31, 0x86, 0x55, 0x05, 0x72, 0x64, 0xe2, 0x8b, 0xc0, 0xb6, 0xfb, 0x37, 0x8c, 0x8e, 0xf1, 0x46, 0xbe, 0x00 };
            Byte[] abKey2 = (new System.Text.UTF8Encoding()).GetBytes("Jefe");
            Byte[] abData2 = (new System.Text.UTF8Encoding()).GetBytes("what do ya want for nothing?");
            Byte[] abDigest2 = { 0xef, 0xfc, 0xdf, 0x6a, 0xe5, 0xeb, 0x2f, 0xa2, 0xd2, 0x74, 0x16, 0xd5, 0xf1, 0x84, 0xdf, 0x9c, 0x25, 0x9a, 0x7c, 0x79 };

            CryptoKey key1 = CryptoKey.LoadKey(session, new CryptokiAttribute[] { 
                    new CryptokiAttribute(CryptokiAttribute.CryptokiType.Class  , Utility.ConvertToBytes((int)CryptokiClass.SECRET_KEY)),
                    new CryptokiAttribute(CryptokiAttribute.CryptokiType.KeyType, Utility.ConvertToBytes((int)CryptoKey.KeyType.GENERIC_SECRET)),
                    new CryptokiAttribute(CryptokiAttribute.CryptokiType.Value  , abKey1)
            });

            CryptoKey key2 = CryptoKey.LoadKey(session, new CryptokiAttribute[] { 
                    new CryptokiAttribute(CryptokiAttribute.CryptokiType.Class  , Utility.ConvertToBytes((int)CryptokiClass.SECRET_KEY)),
                    new CryptokiAttribute(CryptokiAttribute.CryptokiType.KeyType, Utility.ConvertToBytes((int)CryptoKey.KeyType.GENERIC_SECRET)),
                    new CryptokiAttribute(CryptokiAttribute.CryptokiType.Value  , abKey2)
            });

            Log.Comment("Testing rc21 hash...");
            using(KeyedHashAlgorithm rc21 = new KeyedHashAlgorithm(KeyedHashAlgorithmType.HMACSHA1, key1))
            using (KeyedHashAlgorithm rc22 = new KeyedHashAlgorithm(KeyedHashAlgorithmType.HMACSHA1, key2))
            {
                rc21.ComputeHash(abData1);
                rc22.ComputeHash(abData2);
                Log.Comment("The computed hash #1 is : ");
                PrintByteArray(rc21.Hash);
                Log.Comment("The correct hash #1 is : ");
                PrintByteArray(abDigest1);
                if (Compare(rc21.Hash, abDigest1))
                {
                    Log.Comment("CORRECT");
                }
                else
                {
                    Log.Comment("INCORRECT");
                    bRes = false;
                }
                Log.Comment("The computed hash #2 is : ");
                PrintByteArray(rc22.Hash);
                Log.Comment("The correct hash #2 is : ");
                PrintByteArray(abDigest2);
                if (Compare(rc22.Hash, abDigest2))
                {
                    Log.Comment("CORRECT");
                }
                else
                {
                    Log.Comment("INCORRECT");
                    bRes = false;
                }
            }
            return bRes;
        }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:57,代码来源:Hash_HMACSHA1known.cs

示例15: CryptokiDigest

        /// <summary>
        /// Creates the Cryptoki digest object with specified session context, digest algorithm, and hash size.
        /// </summary>
        /// <param name="session">The Cryptoki session context.</param>
        /// <param name="mechanism">The digest algorithm and paramters.</param>
        /// <param name="hashSize">The size of the resulting hash value, in bits.</param>
        public CryptokiDigest(Session session, Mechanism mechanism, int hashSize)
            : base(session, false)
        {
            m_hashSize = (hashSize + 7) / 8;

            if (m_hashSize == 0) throw new ArgumentException();

            m_mechanism = mechanism;
        }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:15,代码来源:Digest.cs


注:本文中的Microsoft.SPOT.Cryptoki.Session类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。