Top Description Fields Constructors Methods
org.apache.commons.compress.archivers.zip

public Class X0017_StrongEncryptionHeader

extends PKWareExtraHeader
Class Inheritance
Imports
java.util.Arrays, java.util.zip.ZipException

Strong Encryption Header (0x0017).

Certificate-based encryption:

Value     Size     Description
-----     ----     -----------
0x0017    2 bytes  Tag for this "extra" block type
TSize     2 bytes  Size of data that follows
Format    2 bytes  Format definition for this record
AlgID     2 bytes  Encryption algorithm identifier
Bitlen    2 bytes  Bit length of encryption key (32-448 bits)
Flags     2 bytes  Processing flags
RCount    4 bytes  Number of recipients.
HashAlg   2 bytes  Hash algorithm identifier
HSize     2 bytes  Hash size
SRList    (var)    Simple list of recipients hashed public keys

Flags -   This defines the processing flags.
RCount - This defines the number intended recipients whose
         public keys were used for encryption.  This identifies
         the number of elements in the SRList.

         see also: reserved1

HashAlg - This defines the hash algorithm used to calculate
          the public key hash of each public key used
          for encryption. This field currently supports
          only the following value for SHA-1

          0x8004 - SHA1

HSize -   This defines the size of a hashed public key.

SRList -  This is a variable length list of the hashed
          public keys for each intended recipient.  Each
          element in this list is HSize.  The total size of
          SRList is determined using RCount * HSize.

Password-based Extra Field 0x0017 in central header only.

Value     Size     Description
-----     ----     -----------
0x0017    2 bytes  Tag for this "extra" block type
TSize     2 bytes  Size of data that follows
Format    2 bytes  Format definition for this record
AlgID     2 bytes  Encryption algorithm identifier
Bitlen    2 bytes  Bit length of encryption key (32-448 bits)
Flags     2 bytes  Processing flags
(more?)

Format - the data format identifier for this record. The only value allowed at this time is the integer value 2.

Password-based Extra Field 0x0017 preceding compressed file data.

Value     Size     Description
-----     ----     -----------
0x0017    2 bytes  Tag for this "extra" block type
IVSize    2 bytes  Size of initialization vector (IV)
IVData    IVSize   Initialization vector for this file
Size      4 bytes  Size of remaining decryption header data
Format    2 bytes  Format definition for this record
AlgID     2 bytes  Encryption algorithm identifier
Bitlen    2 bytes  Bit length of encryption key (32-448 bits)
Flags     2 bytes  Processing flags
ErdSize   2 bytes  Size of Encrypted Random Data
ErdData   ErdSize  Encrypted Random Data
Reserved1 4 bytes  Reserved certificate processing data
Reserved2 (var)    Reserved for certificate processing data
VSize     2 bytes  Size of password validation data
VData     VSize-4  Password validation data
VCRC32    4 bytes  Standard ZIP CRC32 of password validation data

IVData - The size of the IV should match the algorithm block size.
         The IVData can be completely random data.  If the size of
         the randomly generated data does not match the block size
         it should be complemented with zero's or truncated as
         necessary.  If IVSize is 0, then IV = CRC32 + Uncompressed
         File Size (as a 64 bit little-endian, unsigned integer value).

Format -  the data format identifier for this record.  The only
          value allowed at this time is the integer value 2.

ErdData - Encrypted random data is used to store random data that
          is used to generate a file session key for encrypting
          each file.  SHA1 is used to calculate hash data used to
          derive keys.  File session keys are derived from a master
          session key generated from the user-supplied password.
          If the Flags field in the decryption header contains
          the value 0x4000, then the ErdData field must be
          decrypted using 3DES. If the value 0x4000 is not set,
          then the ErdData field must be decrypted using AlgId.

Reserved1 - Reserved for certificate processing, if value is
          zero, then Reserved2 data is absent.  See the explanation
          under the Certificate Processing Method for details on
          this data structure.

Reserved2 - If present, the size of the Reserved2 data structure
          is located by skipping the first 4 bytes of this field
          and using the next 2 bytes as the remaining size.  See
          the explanation under the Certificate Processing Method
          for details on this data structure.

VSize - This size value will always include the 4 bytes of the
        VCRC32 data and will be greater than 4 bytes.

VData - Random data for password validation.  This data is VSize
        in length and VSize must be a multiple of the encryption
        block size.  VCRC32 is a checksum value of VData.
        VData and VCRC32 are stored encrypted and start the
        stream of encrypted data for a file.

Reserved1 - Certificate Decryption Header Reserved1 Data:

Value     Size     Description
-----     ----     -----------
RCount    4 bytes  Number of recipients.

RCount - This defines the number intended recipients whose public keys were used for encryption. This defines the number of elements in the REList field defined below.

Reserved2 - Certificate Decryption Header Reserved2 Data Structures:

Value     Size     Description
-----     ----     -----------
HashAlg   2 bytes  Hash algorithm identifier
HSize     2 bytes  Hash size
REList    (var)    List of recipient data elements

HashAlg - This defines the hash algorithm used to calculate
          the public key hash of each public key used
          for encryption. This field currently supports
          only the following value for SHA-1

              0x8004 - SHA1

HSize -   This defines the size of a hashed public key
          defined in REHData.

REList -  This is a variable length of list of recipient data.
          Each element in this list consists of a Recipient
          Element data structure as follows:

Recipient Element (REList) Data Structure:

Value     Size     Description
-----     ----     -----------
RESize    2 bytes  Size of REHData + REKData
REHData   HSize    Hash of recipients public key
REKData   (var)    Simple key blob


RESize -  This defines the size of an individual REList
          element.  This value is the combined size of the
          REHData field + REKData field.  REHData is defined by
          HSize.  REKData is variable and can be calculated
          for each REList element using RESize and HSize.

REHData - Hashed public key for this recipient.

REKData - Simple Key Blob.  The format of this data structure
          is identical to that defined in the Microsoft
          CryptoAPI and generated using the CryptExportKey()
          function.  The version of the Simple Key Blob
          supported at this time is 0x02 as defined by
          Microsoft.

          For more details see https://msdn.microsoft.com/en-us/library/aa920051.aspx

Flags - Processing flags needed for decryption

See the section describing the Strong Encryption Specification for details. Refer to the section in this document entitled "Incorporating PKWARE Proprietary Technology into Your Product" for more information.

Since
1.11

Field Summary

Modifier and TypeField and Description
private PKWareExtraHeader.EncryptionAlgorithm
private int
private byte[]
private int
private int
private PKWareExtraHeader.HashAlgorithm
private int
pack-priv static final ZipShort
private byte[]
private byte[]
private long
private byte[]
private byte[]
private byte[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
assertDynamicLengthFits(final String what, final int dynamicLength, final int prefixLength, final int length)

public PKWareExtraHeader.EncryptionAlgorithm

Returns:

the encryption algorithm
getEncryptionAlgorithm
()

Gets encryption algorithm.

public PKWareExtraHeader.HashAlgorithm

Returns:

the hash algorithm
getHashAlgorithm
()

Gets hash algorithm.

public long

Returns:

the record count
getRecordCount
()

Gets record count.

public void
parseCentralDirectoryFormat(final byte[]
the buffer to read data from
data
,
final int
offset into buffer to read data
offset
,
final int
the length of data
length
)

Parse central directory format.

public void
parseFileFormat(final byte[]
the buffer to read data from
data
,
final int
offset into buffer to read data
offset
,
final int
the length of data
length
)

Parse file header format.

public void
parseFromCentralDirectoryData(final byte[]
the array of bytes.
data
,
final int
the source location in the data array.
offset
,
final int
the number of bytes to use in the data array.
length
)

Overrides org.apache.commons.compress.archivers.zip.PKWareExtraHeader.parseFromCentralDirectoryData.

Implements org.apache.commons.compress.archivers.zip.ZipExtraField.parseFromCentralDirectoryData.

Populate data from this array as if it was in central directory data.
public void
parseFromLocalFileData(final byte[]
the array of bytes.
data
,
final int
the source location in the data array.
offset
,
final int
the number of bytes to use in the data array.
length
)

Overrides org.apache.commons.compress.archivers.zip.PKWareExtraHeader.parseFromLocalFileData.

Implements org.apache.commons.compress.archivers.zip.ZipExtraField.parseFromLocalFileData.

Populate data from this array as if it was in local file data.
Inherited from org.apache.commons.compress.archivers.zip.PKWareExtraHeader:
assertMinimalLengthgetCentralDirectoryDatagetCentralDirectoryLengthgetHeaderIdgetLocalFileDataDatagetLocalFileDataLengthsetCentralDirectoryDatasetLocalFileDataData

Field Detail

algIdback to summary
private PKWareExtraHeader.EncryptionAlgorithm algId
bitlenback to summary
private int bitlen
erdDataback to summary
private byte[] erdData
flagsback to summary
private int flags
formatback to summary
private int format
hashAlgback to summary
private PKWareExtraHeader.HashAlgorithm hashAlg
hashSizeback to summary
private int hashSize
HEADER_IDback to summary
pack-priv static final ZipShort HEADER_ID
ivDataback to summary
private byte[] ivData
keyBlobback to summary
private byte[] keyBlob
rcountback to summary
private long rcount
recipientKeyHashback to summary
private byte[] recipientKeyHash
vCRC32back to summary
private byte[] vCRC32
vDataback to summary
private byte[] vData

Constructor Detail

X0017_StrongEncryptionHeaderback to summary
public X0017_StrongEncryptionHeader()

Method Detail

assertDynamicLengthFitsback to summary
private void assertDynamicLengthFits(final String what, final int dynamicLength, final int prefixLength, final int length) throws ZipException
getEncryptionAlgorithmback to summary
public PKWareExtraHeader.EncryptionAlgorithm getEncryptionAlgorithm()

Gets encryption algorithm.

Returns:PKWareExtraHeader.EncryptionAlgorithm

the encryption algorithm

getHashAlgorithmback to summary
public PKWareExtraHeader.HashAlgorithm getHashAlgorithm()

Gets hash algorithm.

Returns:PKWareExtraHeader.HashAlgorithm

the hash algorithm

getRecordCountback to summary
public long getRecordCount()

Gets record count.

Returns:long

the record count

parseCentralDirectoryFormatback to summary
public void parseCentralDirectoryFormat(final byte[] data, final int offset, final int length) throws ZipException

Parse central directory format.

Parameters
data:byte[]

the buffer to read data from

offset:int

offset into buffer to read data

length:int

the length of data

Exceptions
ZipException:
if an error occurs
parseFileFormatback to summary
public void parseFileFormat(final byte[] data, final int offset, final int length) throws ZipException

Parse file header format.

(Password only?)

Parameters
data:byte[]

the buffer to read data from

offset:int

offset into buffer to read data

length:int

the length of data

Exceptions
ZipException:
if an error occurs
parseFromCentralDirectoryDataback to summary
public void parseFromCentralDirectoryData(final byte[] data, final int offset, final int length) throws ZipException

Overrides org.apache.commons.compress.archivers.zip.PKWareExtraHeader.parseFromCentralDirectoryData.

Implements org.apache.commons.compress.archivers.zip.ZipExtraField.parseFromCentralDirectoryData.

Doc from org.apache.commons.compress.archivers.zip.ZipExtraField.parseFromCentralDirectoryData.

Populate data from this array as if it was in central directory data.

Parameters
data:byte[]

Doc from org.apache.commons.compress.archivers.zip.PKWareExtraHeader.parseFromCentralDirectoryData.

the array of bytes.

offset:int

Doc from org.apache.commons.compress.archivers.zip.PKWareExtraHeader.parseFromCentralDirectoryData.

the source location in the data array.

length:int

Doc from org.apache.commons.compress.archivers.zip.PKWareExtraHeader.parseFromCentralDirectoryData.

the number of bytes to use in the data array.

Annotations
@Override
Exceptions
ZipException:
on error
parseFromLocalFileDataback to summary
public void parseFromLocalFileData(final byte[] data, final int offset, final int length) throws ZipException

Overrides org.apache.commons.compress.archivers.zip.PKWareExtraHeader.parseFromLocalFileData.

Implements org.apache.commons.compress.archivers.zip.ZipExtraField.parseFromLocalFileData.

Doc from org.apache.commons.compress.archivers.zip.ZipExtraField.parseFromLocalFileData.

Populate data from this array as if it was in local file data.

Parameters
data:byte[]

Doc from org.apache.commons.compress.archivers.zip.PKWareExtraHeader.parseFromLocalFileData.

the array of bytes.

offset:int

Doc from org.apache.commons.compress.archivers.zip.PKWareExtraHeader.parseFromLocalFileData.

the source location in the data array.

length:int

Doc from org.apache.commons.compress.archivers.zip.PKWareExtraHeader.parseFromLocalFileData.

the number of bytes to use in the data array.

Annotations
@Override
Exceptions
ZipException:
on error