Ejemplo n.º 1
0
        public void TestGenerateKey32()
        {
            var originalKey = new byte[32];
            var expectedKey = new byte[]
            {
                0xF0, 0xED, 0x57, 0xD5, 0xF0, 0xDA, 0xF3, 0x47,
                0x90, 0xD0, 0xDB, 0x43, 0x25, 0xC6, 0x81, 0x2C,
                0x81, 0x6A, 0x0D, 0x94, 0x96, 0xA9, 0x03, 0xE1,
                0x20, 0xD4, 0x3A, 0x3E, 0x45, 0xAD, 0x02, 0x65
            };
            const ulong rounds = 1;

            var           composite = new CompositeKey();
            AesKdf        kdf       = new AesKdf();
            KdfParameters p         = kdf.GetDefaultParameters();

            p.SetUInt64(AesKdf.ParamRounds, rounds);
            p.SetByteArray(AesKdf.ParamSeed, originalKey);
            var key = composite.GenerateKey32(p);

            Assert.NotNull(key);
            var keyData = key.ReadData();

            Assert.True(MemUtil.ArraysEqual(keyData, expectedKey));
        }
Ejemplo n.º 2
0
        public void TestGenerateKey32()
        {
            var originalKey = new byte[32];
            var expectedKey = new byte[32] {
                0xF0, 0xED, 0x57, 0xD5, 0xF0, 0xDA, 0xF3, 0x47,
                0x90, 0xD0, 0xDB, 0x43, 0x25, 0xC6, 0x81, 0x2C,
                0x81, 0x6A, 0x0D, 0x94, 0x96, 0xA9, 0x03, 0xE1,
                0x20, 0xD4, 0x3A, 0x3E, 0x45, 0xAD, 0x02, 0x65
            };
            const ulong rounds = 1;

            var composite = new CompositeKey();
            var key       = composite.GenerateKey32(originalKey, rounds);

            Assert.That(key, Is.Not.Null);
            var keyData = key.ReadData();

            Assert.That(keyData, Is.EqualTo(expectedKey));
        }
Ejemplo n.º 3
0
        private byte[] GetKey()
        {
            byte[]       ThreeDESKey = new byte[24];
            MemoryStream ms          = new MemoryStream();

            ms.Write(m_MasterSeed, 0, 32);

            KdfParameters kdf = new AesKdf().GetDefaultParameters();

            kdf.SetUInt64(AesKdf.ParamRounds, m_NumRounds);
            kdf.SetByteArray(AesKdf.ParamSeed, m_TransformSeed);

            ProtectedBinary pbinKey = m_2Key.GenerateKey32(kdf);

            if (pbinKey == null)
            {
                throw new SecurityException("Invalid Key");
            }

            byte[] pKey32 = pbinKey.ReadData();
            if ((pKey32 == null) || (pKey32.Length != 32))
            {
                throw new SecurityException("Invalid Key Data");
            }

            ms.Write(pKey32, 0, 32);

            byte[] sRandom = m_hash.Hash;
            ms.Write(sRandom, 0, sRandom.Length);

            SHA256Managed sha = new SHA256Managed();

            byte[] Key256 = sha.ComputeHash(ms.ToArray());

            Array.Copy(Key256, ThreeDESKey, ThreeDESKey.Length);

            ms.Close();

            Array.Clear(pKey32, 0, 32);
            Array.Clear(Key256, 0, 32);

            return(ThreeDESKey);
        }