本文整理汇总了C#中Microsoft.SPOT.Cryptoki.Session类的典型用法代码示例。如果您正苦于以下问题:C# Session类的具体用法?C# Session怎么用?C# Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Session类属于Microsoft.SPOT.Cryptoki命名空间,在下文中一共展示了Session类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: X509Certificate2
/// <summary>
/// Initializes a new instance of the X509Certificate2 class from a byte array
/// </summary>
/// <param name="session">Cryptoki session for which this certificate will be created</param>
/// <param name="data">Data bytes for the certificate (PEM, DER, P12, etc.)</param>
/// <param name="password">Password for decrypting the certificate data (optional)</param>
public X509Certificate2(Session session, byte[] data, string password="")
{
if (data == null || data.Length == 0)
throw new ArgumentException();
m_cert = CryptokiCertificate.LoadCertificate(session, data, password);
Init();
}
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:15,代码来源:X509Certificate2.cs
示例17: SessionContainer
/// <summary>
/// Creates a session container object with the specified session context.
/// </summary>
/// <param name="session">The Cryptoki session context.</param>
/// <param name="ownsSession">Determines if the container disposes the session object.</param>
protected SessionContainer(Session session, bool ownsSession)
{
m_ownsSession = ownsSession;
m_session = session;
if (!ownsSession)
{
session.AddSessionObject(this);
}
}
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:15,代码来源:Session.cs
示例18: RunRoundTrip
/// <summary>
/// Run a round trip test -- the data should encrypt and decrypt back to itself
/// </summary>
/// <param name="key">key to use</param>
/// <param name="iv">IV to use</param>
/// <param name="text">data to encrypt</param>
/// <param name="padding">padding method to use</param>
/// <returns>true if text encrypted and decrypted back to itself</returns>
protected bool RunRoundTrip(Session session, byte[] key, byte[] iv, byte[] text, PaddingMode padding)
{
try
{
Log.Comment("Encrypting the following bytes:");
PrintByteArray(text);
// setup the encryption provider
AesCryptoServiceProvider aes = new AesCryptoServiceProvider(CryptoKey.ImportKey(session, key, CryptoKey.KeyClass.Secret, CryptoKey.KeyType.AES, true));
aes.IV = iv;
aes.Mode = CipherMode.ECB;
aes.Padding = padding;
// encrypt the data
ICryptoTransform sse = aes.CreateEncryptor();
//MemoryStream ms = new MemoryStream();
//CryptoStream cs = new CryptoStream(ms, sse, CryptoStreamMode.Write);
//cs.Write(text, 0, text.Length);
//cs.FlushFinalBlock();
byte[] cipherText = sse.TransformFinalBlock(text, 0, text.Length); //ms.ToArray();
//cs.Close();
Log.Comment("Cyphertext:");
PrintByteArray(cipherText);
Log.Comment("Decrypting...");
ICryptoTransform ssd = aes.CreateDecryptor();
//cs = new CryptoStream(new MemoryStream(cipherText), ssd, CryptoStreamMode.Read);
// decrypt the data
byte[] newPlainText = ssd.TransformFinalBlock(cipherText, 0, cipherText.Length); // new byte[text.Length];
//cs.Read(newPlainText, 0, text.Length);
Log.Comment("Plaintext:");
PrintByteArray(newPlainText);
// make sure the roundtrip worked
if (!Compare(text, newPlainText))
{
Log.Comment("ERROR: roundtrip failed");
return false;
}
}
catch (NotSupportedException)
{
throw;
}
catch
{
return false;
}
return true;
}
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:63,代码来源:PaddingBase.cs
示例19: RsaTest_ExportImportTest
public MFTestResults RsaTest_ExportImportTest()
{
bool testResult = true;
try
{
using (Session session = new Session("", MechanismType.RSA_PKCS))
using (CryptoKey privateKey = CryptoKey.LoadKey(session, m_importKeyPrivate))
{
string dataToSign = "This is a simple message to be encrypted";
byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(dataToSign);
using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(privateKey))
{
RSAParameters kp1 = rsa.ExportParameters(true);
byte[] sig = rsa.SignData(data);
rsa.ImportParameters(kp1);
RSAParameters kp2 = rsa.ExportParameters(true);
testResult &= CompareByteArray(kp1.D, kp2.D);
testResult &= CompareByteArray(kp1.DP, kp2.DP);
testResult &= CompareByteArray(kp1.DQ, kp2.DQ);
testResult &= CompareByteArray(kp1.Exponent, kp2.Exponent);
testResult &= CompareByteArray(kp1.InverseQ, kp2.InverseQ);
testResult &= CompareByteArray(kp1.Modulus, kp2.Modulus);
testResult &= CompareByteArray(kp1.P, kp2.P);
testResult &= CompareByteArray(kp1.Q, kp2.Q);
testResult &= CompareByteArray(m_importKeyPrivate[2].Value, kp1.Modulus);
testResult &= CompareByteArray(m_importKeyPrivate[3].Value, kp1.Exponent);
testResult &= CompareByteArray(m_importKeyPrivate[4].Value, kp1.D);
testResult &= CompareByteArray(m_importKeyPrivate[5].Value, kp1.P);
testResult &= CompareByteArray(m_importKeyPrivate[6].Value, kp1.Q);
testResult &= CompareByteArray(m_importKeyPrivate[7].Value, kp1.DP);
testResult &= CompareByteArray(m_importKeyPrivate[8].Value, kp1.DQ);
testResult &= CompareByteArray(m_importKeyPrivate[9].Value, kp1.InverseQ);
testResult &= rsa.VerifyData(data, sig);
}
}
}
catch (Exception ex)
{
Log.Exception("Unexpected Exception", ex);
testResult = false;
}
return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
}
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:55,代码来源:RSATest.cs
示例20: InitAlgorithmList
// The SHA{256,284,512}CSP algorithms are only supported on Win2k3 and higher (version 5.2+)
//
public static void InitAlgorithmList(Session s1, Session s2)
{
m_AlgorithmPairs = new AlgorithmPairs[] {
new AlgorithmPairs( new HashAlgorithm(HashAlgorithmType.SHA1 , s1), new HashAlgorithm(HashAlgorithmType.SHA1 , s2) ),
new AlgorithmPairs( new HashAlgorithm(HashAlgorithmType.SHA256, s1), new HashAlgorithm(HashAlgorithmType.SHA256, s2) ),
new AlgorithmPairs( new HashAlgorithm(HashAlgorithmType.SHA384, s1), new HashAlgorithm(HashAlgorithmType.SHA384, s2) ),
new AlgorithmPairs( new HashAlgorithm(HashAlgorithmType.SHA512, s1), new HashAlgorithm(HashAlgorithmType.SHA512, s2) ),
new AlgorithmPairs( new HashAlgorithm(HashAlgorithmType.MD5 , s1), new HashAlgorithm(HashAlgorithmType.MD5 , s2) ),
};
}
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:13,代码来源:HashCompare.cs
注:本文中的Microsoft.SPOT.Cryptoki.Session类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论