示例#1
0
        public void Write(LittleEndianByteArrayOutputStream bos)
        {
            // see [MS-OFFCRYPTO] - 2.3.4.9
            byte[] salt = Salt;
            Debug.Assert(salt.Length == 16);
            bos.WriteInt(salt.Length); // salt size
            bos.Write(salt);

            // The resulting Verifier value MUST be an array of 16 bytes.
            byte[] encryptedVerifier = EncryptedVerifier;
            Debug.Assert(encryptedVerifier.Length == 16);
            bos.Write(encryptedVerifier);

            // The number of bytes used by the decrypted Verifier hash is given by
            // the VerifierHashSize field, which MUST be 20
            bos.WriteInt(20);

            // EncryptedVerifierHash: An array of bytes that Contains the encrypted form of the hash of
            // the randomly generated Verifier value. The length of the array MUST be the size of the
            // encryption block size multiplied by the number of blocks needed to encrypt the hash of the
            // Verifier. If the encryption algorithm is RC4, the length MUST be 20 bytes. If the encryption
            // algorithm is AES, the length MUST be 32 bytes. After decrypting the EncryptedVerifierHash
            // field, only the first VerifierHashSize bytes MUST be used.
            byte[] encryptedVerifierHash = EncryptedVerifierHash;
            Debug.Assert(encryptedVerifierHash.Length == CipherAlgorithm.encryptedVerifierHashLength);
            bos.Write(encryptedVerifierHash);
        }
        //protected internal void SetEncryptedVerifier(byte[] encryptedVerifier)
        //{
        //    base.EncryptedVerifier = (encryptedVerifier);
        //}

        //protected internal void SetEncryptedVerifierHash(byte[] encryptedVerifierHash)
        //{
        //    base.EncryptedVerifierHash = (encryptedVerifierHash);
        //}

        public void Write(LittleEndianByteArrayOutputStream bos)
        {
            byte[] salt = Salt;
            Debug.Assert(salt.Length == 16);
            bos.Write(salt);
            byte[] encryptedVerifier = EncryptedVerifier;
            Debug.Assert(encryptedVerifier.Length == 16);
            bos.Write(encryptedVerifier);
            byte[] encryptedVerifierHash = EncryptedVerifierHash;
            Debug.Assert(encryptedVerifierHash.Length == 16);
            bos.Write(encryptedVerifierHash);
        }
示例#3
0
        public override int Serialize(int offset, byte [] data)
        {
            int recSize  = RecordSize;
            int dataSize = recSize - 4;

            LittleEndianByteArrayOutputStream out1 = new LittleEndianByteArrayOutputStream(data, offset, recSize);

            out1.WriteShort(sid);
            out1.WriteShort(dataSize);

            if (_uninterpretedData == null)
            {
                for (int i = 0; i < subrecords.Count; i++)
                {
                    SubRecord record = subrecords[i];
                    record.Serialize(out1);
                }
                int expectedEndIx = offset + dataSize;
                // padding
                while (out1.WriteIndex < expectedEndIx)
                {
                    out1.WriteByte(0);
                }
            }
            else
            {
                out1.Write(_uninterpretedData);
            }
            return(recSize);
        }
示例#4
0
        /**
         * Serializes the header
         */
        public void Write(LittleEndianByteArrayOutputStream bos)
        {
            int startIdx = bos.WriteIndex;
            ILittleEndianOutput sizeOutput = bos.CreateDelayedOutput(LittleEndianConsts.INT_SIZE);

            bos.WriteInt(Flags);
            bos.WriteInt(0); // size extra
            bos.WriteInt(CipherAlgorithm.ecmaId);
            bos.WriteInt(HashAlgorithm.ecmaId);
            bos.WriteInt(KeySize);
            bos.WriteInt(CipherProvider.ecmaId);
            bos.WriteInt(0); // reserved1
            bos.WriteInt(0); // reserved2
            String cspName = CspName;

            if (cspName == null)
            {
                cspName = CipherProvider.cipherProviderName;
            }
            bos.Write(StringUtil.GetToUnicodeLE(cspName));
            bos.WriteShort(0);
            int headerSize = bos.WriteIndex - startIdx - LittleEndianConsts.INT_SIZE;

            sizeOutput.WriteInt(headerSize);
        }
示例#5
0
        protected void marshallEncryptionDocument(EncryptionDocument ed, LittleEndianByteArrayOutputStream os)
        {
            //XmlOptions xo = new XmlOptions();
            //xo.SetCharacterEncoding("UTF-8");
            Dictionary <String, String> nsMap = new Dictionary <String, String>();

            nsMap.Add(passwordUri.ToString(), "p");
            nsMap.Add(certificateUri.ToString(), "c");
            //xo.UseDefaultNamespace();
            //xo.SaveSuggestedPrefixes(nsMap);
            //xo.SaveNamespacesFirst();
            //xo.SaveAggressiveNamespaces();

            // Setting standalone doesn't work with xmlbeans-2.3 & 2.6
            // ed.DocumentProperties().Standalone=(/*setter*/true);
            //xo.SaveNoXmlDecl();
            MemoryStream bos = new MemoryStream();

            try {
                byte[] buf = Encoding.UTF8.GetBytes("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\r\n");
                bos.Write(buf, 0, buf.Length);
                ed.Save(bos);
                os.Write(bos.ToArray());
            } catch (IOException e) {
                throw new EncryptedDocumentException("error marshalling encryption info document", e);
            }
        }
示例#6
0
        public override int Serialize(int offset, byte [] data)
        {
            int recSize = RecordSize;
            int dataSize = recSize - 4;

            LittleEndianByteArrayOutputStream out1 = new LittleEndianByteArrayOutputStream(data, offset, recSize);

            out1.WriteShort(sid);
            out1.WriteShort(dataSize);

            if (_uninterpretedData == null)
            {
                for (int i = 0; i < subrecords.Count; i++)
                {
                    SubRecord record = subrecords[i];
                    record.Serialize(out1);
                }
                int expectedEndIx = offset + dataSize;
                // padding
                while (out1.WriteIndex < expectedEndIx)
                {
                    out1.WriteByte(0);
                }
            }
            else
            {
                out1.Write(_uninterpretedData);
            }
            return recSize;
        }