/// <summary> /// Constructs a DtmForwardKeyStruct from a stream /// </summary> /// /// <param name="SessionStream">Stream containing a serialized DtmForwardKeyStruct</param> /// /// <returns>A populated DtmForwardKeyStruct</returns> public DtmForwardKeyStruct(Stream SessionStream) { BinaryReader reader = new BinaryReader(SessionStream); Key = KeyParams.DeSerialize(SessionStream); SessionParams = new DtmSessionStruct(SessionStream); LifeSpan = reader.ReadInt64(); Instruction = reader.ReadInt16(); OptionsFlag = reader.ReadInt64(); }
/// <summary> /// Extract a KeyParams and CipherKey /// </summary> /// /// <param name="KeyHeader">The <see cref="VTDev.Libraries.CEXEngine.Crypto.Processing.Structure.CipherKey"/> that receives the cipher description, key id, and extension key</param> /// <param name="KeyParam">The <see cref="VTDev.Libraries.CEXEngine.Crypto.Common.KeyParams"/> container that receives the key material from the file</param> /// /// <exception cref="CryptoProcessingException">Thrown if the key file could not be found or a Header parameter does not match the keystream length</exception> public void Extract(out CipherKey KeyHeader, out KeyParams KeyParam) { m_keyStream.Seek(0, SeekOrigin.Begin); KeyHeader = new CipherKey(m_keyStream); CipherDescription dsc = KeyHeader.Description; if (m_keyStream.Length < dsc.KeySize + dsc.IvSize + dsc.MacKeySize + CipherKey.GetHeaderSize()) { throw new CryptoProcessingException("KeyFactory:Extract", "The size of the key file does not align with the CipherKey sizes! Key is corrupt.", new ArgumentOutOfRangeException()); } m_keyStream.Seek(CipherKey.GetHeaderSize(), SeekOrigin.Begin); KeyParam = KeyParams.DeSerialize(m_keyStream); }
private void KeyParamsTest() { CSPPrng rnd = new CSPPrng(); KeyGenerator kg = new KeyGenerator(); for (int i = 0; i < 10; ++i) { // out-bound funcs return pointer to obj KeyParams kp1 = kg.GetKeyParams(rnd.Next(1, 1024), rnd.Next(1, 128), rnd.Next(1, 128)); MemoryStream m = (MemoryStream)KeyParams.Serialize(kp1); KeyParams kp2 = KeyParams.DeSerialize(m); if (!kp1.Equals(kp2)) { throw new Exception("KeyFactoryTest: KeyParams serialization test has failed!"); } if (kp1.GetHashCode() != kp2.GetHashCode()) { throw new Exception("KeyFactoryTest: KeyAuthority hash code test has failed!"); } } }