/// <summary> /// Generates a random symmetric key for use in the signing process. /// </summary> /// <param name="keySize">Size of the symmetric key in bits</param> private void GenerateKey(int keySize) { CryptokiAttribute[] attribs = new CryptokiAttribute[] { new CryptokiAttribute(CryptokiAttribute.CryptokiType.ValueLen, Utility.ConvertToBytes(keySize)) }; KeyValue = CryptoKey.GenerateKey(m_session, new Mechanism(MechanismType.GENERIC_SECRET_KEY_GEN), attribs); OwnsKey = true; m_mechanism.Parameter = KeyValue.Handle; Initialize(); }
/// <summary> /// Generates a random key to use for the algorithm. /// </summary> public override void GenerateKey() { CryptoKey key; Mechanism mech = new Mechanism(Microsoft.SPOT.Cryptoki.MechanismType.AES_KEY_GEN); CryptokiAttribute[] attribs = new CryptokiAttribute[] { new CryptokiAttribute(CryptokiAttribute.CryptokiType.ValueLen, Utility.ConvertToBytes(KeySizeValue)) }; key = CryptoKey.GenerateKey(m_session, mech, attribs); if (KeyValue != null && OwnsKey) { KeyValue.Dispose(); } KeyValue = key; OwnsKey = true; }