public byte[] toByteArray() { byte[] result = new byte[LittleEndianConsts.INT_SIZE*2+_value.length]; LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(result,0); try { bos.writeInt(LittleEndianConsts.INT_SIZE + _value.length); bos.writeInt(_format); bos.write(_value); return result; } finally { IOUtils.closeQuietly(bos); } }
@Override public int serialize(int offset, byte[] data) { int recSize = getRecordSize(); int dataSize = recSize - 4; LittleEndianByteArrayOutputStream out = new LittleEndianByteArrayOutputStream(data, offset, recSize); // NOSONAR out.writeShort(sid); out.writeShort(dataSize); if (_uninterpretedData == null) { for (int i = 0; i < subrecords.size(); i++) { SubRecord record = subrecords.get(i); record.serialize(out); } int expectedEndIx = offset+dataSize; // padding while (out.getWriteIndex() < expectedEndIx) { out.writeByte(0); } } else { out.write(_uninterpretedData); } return recSize; }
/** * serializes the header */ @Override public void write(LittleEndianByteArrayOutputStream bos) { int startIdx = bos.getWriteIndex(); LittleEndianOutput sizeOutput = bos.createDelayedOutput(LittleEndianConsts.INT_SIZE); bos.writeInt(getFlags()); bos.writeInt(0); // size extra bos.writeInt(getCipherAlgorithm().ecmaId); bos.writeInt(getHashAlgorithm().ecmaId); bos.writeInt(getKeySize()); bos.writeInt(getCipherProvider().ecmaId); bos.writeInt(0); // reserved1 bos.writeInt(0); // reserved2 String cspName = getCspName(); if (cspName == null) { cspName = getCipherProvider().cipherProviderName; } bos.write(StringUtil.getToUnicodeLE(cspName)); bos.writeShort(0); int headerSize = bos.getWriteIndex()-startIdx-LittleEndianConsts.INT_SIZE; sizeOutput.writeInt(headerSize); }
public int serialize(int offset, byte[] data) { int recSize = getRecordSize(); int dataSize = recSize - 4; LittleEndianByteArrayOutputStream out = new LittleEndianByteArrayOutputStream(data, offset, recSize); out.writeShort(sid); out.writeShort(dataSize); if (_uninterpretedData == null) { for (int i = 0; i < subrecords.size(); i++) { SubRecord record = subrecords.get(i); record.serialize(out); } int expectedEndIx = offset+dataSize; // padding while (out.getWriteIndex() < expectedEndIx) { out.writeByte(0); } } else { out.write(_uninterpretedData); } return recSize; }
/** * serializes the header */ @Override public void write(LittleEndianByteArrayOutputStream bos) { int startIdx = bos.getWriteIndex(); LittleEndianOutput sizeOutput = bos.createDelayedOutput(LittleEndianConsts.INT_SIZE); bos.writeInt(getFlags()); bos.writeInt(0); // size extra bos.writeInt(getCipherAlgorithm().ecmaId); bos.writeInt(getHashAlgorithm().ecmaId); bos.writeInt(getKeySize()); bos.writeInt(getCipherProvider().ecmaId); bos.writeInt(0); // reserved1 bos.writeInt(0); // reserved2 String cspName = getCspName(); if (cspName == null) { cspName = getCipherProvider().cipherProviderName; } bos.write(StringUtil.getToUnicodeLE(cspName)); bos.writeShort(0); int headerSize = bos.getWriteIndex()-startIdx-LittleEndianConsts.INT_SIZE; sizeOutput.writeInt(headerSize); }
@Override public void write(LittleEndianByteArrayOutputStream bos) { // see [MS-OFFCRYPTO] - 2.3.4.9 byte salt[] = getSalt(); 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[] = getEncryptedVerifier(); 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[] = getEncryptedVerifierHash(); assert(encryptedVerifierHash.length == getCipherAlgorithm().encryptedVerifierHashLength); bos.write(encryptedVerifierHash); }
@Override public void write(LittleEndianByteArrayOutputStream bos) { byte salt[] = getSalt(); assert (salt.length == 16); bos.write(salt); byte encryptedVerifier[] = getEncryptedVerifier(); assert (encryptedVerifier.length == 16); bos.write(encryptedVerifier); byte encryptedVerifierHash[] = getEncryptedVerifierHash(); assert (encryptedVerifierHash.length == 16); bos.write(encryptedVerifierHash); }
public int serialize(int offset, byte[] data) { int recSize = getRecordSize(); int dataSize = recSize - 4; LittleEndianByteArrayOutputStream out = new LittleEndianByteArrayOutputStream(data, offset, recSize); out.writeShort(sid); out.writeShort(dataSize); if (_uninterpretedData == null) { for (int i = 0; i < subrecords.size(); i++) { SubRecord record = subrecords.get(i); record.serialize(out); } int expectedEndIx = offset+dataSize; // padding while (out.getWriteIndex() < expectedEndIx) { out.writeByte(0); } } else { out.write(_uninterpretedData); } return recSize; }
public byte[] toByteArray() { byte[] result = new byte[LittleEndianConsts.INT_SIZE*2+_value.length]; LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(result,0); try { bos.writeInt(LittleEndianConsts.INT_SIZE + _value.length); bos.writeInt(_format); bos.write(_value); return result; } finally { IOUtils.closeQuietly(bos); } }
@Override public int serialize(int offset, byte[] data) { int recSize = getRecordSize(); int dataSize = recSize - 4; LittleEndianByteArrayOutputStream out = new LittleEndianByteArrayOutputStream(data, offset, recSize); // NOSONAR out.writeShort(sid); out.writeShort(dataSize); if (_uninterpretedData == null) { for (int i = 0; i < subrecords.size(); i++) { SubRecord record = subrecords.get(i); record.serialize(out); } int expectedEndIx = offset+dataSize; // padding while (out.getWriteIndex() < expectedEndIx) { out.writeByte(0); } } else { out.write(_uninterpretedData); } return recSize; }
@Override public void write(LittleEndianByteArrayOutputStream bos) { // see [MS-OFFCRYPTO] - 2.3.4.9 byte salt[] = getSalt(); 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[] = getEncryptedVerifier(); 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[] = getEncryptedVerifierHash(); assert(encryptedVerifierHash.length == getCipherAlgorithm().encryptedVerifierHashLength); bos.write(encryptedVerifierHash); }
@Override public void write(LittleEndianByteArrayOutputStream bos) { byte salt[] = getSalt(); assert (salt.length == 16); bos.write(salt); byte encryptedVerifier[] = getEncryptedVerifier(); assert (encryptedVerifier.length == 16); bos.write(encryptedVerifier); byte encryptedVerifierHash[] = getEncryptedVerifierHash(); assert (encryptedVerifierHash.length == 16); bos.write(encryptedVerifierHash); }