@NotMutable @ThreadSafety(level=MOSTLY_THREADSAFE) public final class PassphraseEncryptedStreamHeader extends java.lang.Object implements java.io.Serializable
PassphraseEncryptedOutputStream
when writing encrypted data, and that will be used by a
PassphraseEncryptedInputStream
to obtain the settings needed to
decrypt the encrypted data.
Modifier and Type | Field and Description |
---|---|
static byte[] |
MAGIC_BYTES
The "magic" value that will appear at the start of the header.
|
Modifier and Type | Method and Description |
---|---|
static PassphraseEncryptedStreamHeader |
decode(byte[] encodedHeader,
char[] passphrase)
Decodes the contents of the provided byte array as a passphrase-encrypted
stream header.
|
byte[] |
getCipherInitializationVector()
Retrieves the cipher initialization vector used for the encryption.
|
java.lang.String |
getCipherTransformation()
Retrieves the cipher transformation used for the encryption.
|
byte[] |
getEncodedHeader()
Retrieves an encoded representation of this passphrase-encrypted stream
header.
|
java.lang.String |
getKeyFactoryAlgorithm()
Retrieves the key factory algorithm used to generate the encryption key
from the passphrase.
|
int |
getKeyFactoryIterationCount()
Retrieves the iteration count used to generate the encryption key from the
passphrase.
|
int |
getKeyFactoryKeyLengthBits()
Retrieves the length (in bits) of the encryption key generated from the
passphrase.
|
byte[] |
getKeyFactorySalt()
Retrieves the salt used to generate the encryption key from the passphrase.
|
java.lang.String |
getKeyIdentifier()
Retrieves the key identifier used to associate this passphrase-encrypted
stream header with some other encryption settings object, if defined.
|
java.lang.String |
getMACAlgorithm()
Retrieves the algorithm used to generate a MAC of the header content.
|
boolean |
isSecretKeyAvailable()
Indicates whether this passphrase-encrypted stream header includes a secret
key.
|
static PassphraseEncryptedStreamHeader |
readFrom(java.io.InputStream inputStream,
char[] passphrase)
Reads a passphrase-encrypted stream header from the provided input stream.
|
java.lang.String |
toString()
Retrieves a string representation of this passphrase-encrypted stream
header.
|
void |
toString(java.lang.StringBuilder buffer)
Appends a string representation of this passphrase-encrypted stream header
to the provided buffer.
|
void |
writeTo(java.io.OutputStream outputStream)
Writes an encoded representation of this passphrase-encrypted stream header
to the provided output stream.
|
@NotNull public static final byte[] MAGIC_BYTES
public void writeTo(@NotNull java.io.OutputStream outputStream) throws java.io.IOException
outputStream
- The output stream to which the header will be
written.java.io.IOException
- If a problem is encountered while trying to write to
the provided output stream.@NotNull public static PassphraseEncryptedStreamHeader readFrom(@NotNull java.io.InputStream inputStream, @Nullable char[] passphrase) throws java.io.IOException, LDAPException, java.security.InvalidKeyException, java.security.GeneralSecurityException
inputStream
- The input stream from which to read the encoded
passphrase-encrypted stream header. It must not be
null
.passphrase
- The passphrase to use to generate the encryption key.
If this is null
, then the header will be
read, but no attempt will be made to validate the MAC,
and it will not be possible to use this header to
actually perform encryption or decryption. Providing
a null
value is primarily useful if
information in the header (especially the key
identifier) is needed to determine what passphrase to
use.java.io.IOException
- If a problem is encountered while attempting to read
data from the provided input stream.LDAPException
- If a problem is encountered while attempting to
decode the data that was read.java.security.InvalidKeyException
- If the MAC contained in the header does not
match the expected value.java.security.GeneralSecurityException
- If a problem is encountered while trying
to generate the MAC.@NotNull public static PassphraseEncryptedStreamHeader decode(@NotNull byte[] encodedHeader, @Nullable char[] passphrase) throws LDAPException, java.security.InvalidKeyException, java.security.GeneralSecurityException
encodedHeader
- The bytes that comprise the header to decode. It
must not be null
or empty.passphrase
- The passphrase to use to generate the encryption
key. If this is null
, then the header will
be read, but no attempt will be made to validate the
MAC, and it will not be possible to use this header
to actually perform encryption or decryption.
Providing a null
value is primarily useful
if information in the header (especially the key
identifier) is needed to determine what passphrase
to use.LDAPException
- If a problem is encountered while trying to decode
the data as a passphrase-encrypted stream header.java.security.InvalidKeyException
- If the MAC contained in the header does not
match the expected value.java.security.GeneralSecurityException
- If a problem is encountered while trying
to generate the MAC.@NotNull public java.lang.String getKeyFactoryAlgorithm()
public int getKeyFactoryIterationCount()
@NotNull public byte[] getKeyFactorySalt()
public int getKeyFactoryKeyLengthBits()
@NotNull public java.lang.String getCipherTransformation()
@NotNull public byte[] getCipherInitializationVector()
@Nullable public java.lang.String getKeyIdentifier()
null
if none was provided.@NotNull public java.lang.String getMACAlgorithm()
@NotNull public byte[] getEncodedHeader()
public boolean isSecretKeyAvailable()
true
if this passphrase-encrypted stream header includes a
secret key and can be used to encrypt or decrypt data, or
false
if not.@NotNull public java.lang.String toString()
toString
in class java.lang.Object