Exemplo n.º 1
0
        private void CipherDescriptionTest()
        {
            CipherDescription cd1 = new CipherDescription(
                SymmetricEngines.RHX,
                192, IVSizes.V128,
                CipherModes.CTR,
                PaddingModes.None,
                BlockSizes.B128,
                RoundCounts.R22);

            byte[]            bcd = cd1.ToBytes();
            CipherDescription cd2 = new CipherDescription(bcd);

            if (!cd1.Equals(cd2))
            {
                throw new Exception("KeyFactoryTest: CipherDescription serialization has failed!");
            }
            MemoryStream      mcd = cd2.ToStream();
            CipherDescription cd3 = new CipherDescription(mcd);

            if (!cd1.Equals(cd3))
            {
                throw new Exception("KeyFactoryTest: CipherDescription serialization has failed!");
            }

            int x = cd1.GetHashCode();

            if (x != cd2.GetHashCode() || x != cd3.GetHashCode())
            {
                throw new Exception("KeyFactoryTest: CipherDescription hash code test has failed!");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Convert the PackageKey structure to a MemoryStream
        /// </summary>
        ///
        /// <returns>The MemoryStream containing the PackageKey</returns>
        public MemoryStream ToStream()
        {
            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);

            writer.Write(KeyPolicy);
            writer.Write(CreatedOn);
            writer.Write(Authority.ToBytes());
            writer.Write(Description.ToBytes());
            writer.Write(SubKeyCount);

            byte[] buffer = new byte[SubKeyCount * KEYPOL_SIZE];
            Buffer.BlockCopy(SubKeyPolicy, 0, buffer, 0, buffer.Length);
            writer.Write(buffer);

            buffer = new byte[SubKeyCount * KEYID_SIZE];

            for (int i = 0; i < SubKeyCount; i++)
            {
                Buffer.BlockCopy(SubKeyID[i], 0, buffer, i * KEYID_SIZE, KEYID_SIZE);
            }

            writer.Write(buffer);
            stream.Seek(0, SeekOrigin.Begin);

            return(stream);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Convert the CipherKey structure to a MemoryStream
        /// </summary>
        ///
        /// <returns>The MemoryStream containing the CipherKey</returns>
        public MemoryStream ToStream()
        {
            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);

            writer.Write(Description.ToBytes());
            writer.Write(KeyId);
            writer.Write(ExtensionKey);
            stream.Seek(0, SeekOrigin.Begin);

            return(stream);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Convert the VolumeKey structure to a MemoryStream
        /// </summary>
        ///
        /// <returns>The MemoryStream containing the VolumeKey</returns>
        public MemoryStream ToStream()
        {
            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);

            writer.Write(Tag);
            writer.Write(Description.ToBytes());
            writer.Write(Count);

            for (int i = 0; i < Count; i++)
            {
                writer.Write(FileId[i]);
            }

            writer.Write(State, 0, State.Length);
            stream.Seek(0, SeekOrigin.Begin);

            return(stream);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Set the CipherDescription structure
 /// </summary>
 ///
 /// <param name="KeyStream">The stream containing a key package</param>
 /// <param name="Description">The CipherDescription structure</param>
 public static void SetCipherDescription(Stream KeyStream, CipherDescription Description)
 {
     KeyStream.Seek(CPRDSC_SEEK, SeekOrigin.Begin);
     new BinaryWriter(KeyStream).Write(Description.ToBytes());
 }