Performs a digest operation on a String message.
The steps taken for creating the digest are:
- The String message is converted to a byte array.
- A salt of the specified size is generated (see {@link org.jasypt.salt.SaltGenerator}).
- The salt bytes are added to the message.
- The hash function is applied to the salt and message altogether, and then to the results of the function itself, as many times as specified (iterations).
- If specified by the salt generator (see {@link org.jasypt.salt.SaltGenerator#includePlainSaltInEncryptionResults()}), the undigested salt and the final result of the hash function are concatenated and returned as a result.
- The result of the concatenation is encoded in BASE64 (default) or HEXADECIMAL and returned as an ASCII String.
Put schematically in bytes:
- DIGEST = |S|..(ssb)..|S|X|X|X|...|X|
- S: salt bytes (plain, not digested). (OPTIONAL).
- ssb: salt size in bytes.
- X: bytes resulting from hashing (see below).
- |X|X|X|...|X| = H(H(H(..(it)..H(Z|Z|Z|...|Z|))))
- H: Hash function (algorithm).
- it: Number of iterations.
- Z: Input for hashing (see below).
- |Z|Z|Z|...|Z| = |S|..(ssb)..|S|M|M|M...|M|
- S: salt bytes (plain, not digested).
- ssb: salt size in bytes.
- M: message bytes.
If a random salt generator is used, two digests created for the same message will always be different (except in the case of random salt coincidence). Because of this, in this case the result of the digest method will contain both the undigested salt and the digest of the (salt + message), so that another digest operation can be performed with the same salt on a different message to check if both messages match (all of which will be managed automatically by the matches method).
@param message the String to be digested
@return the digest result
@throws EncryptionOperationNotPossibleException if the digest operationfails, ommitting any further information about the cause for security reasons.
@throws EncryptionInitializationException if initialization could notbe correctly done (for example, if the digest algorithm chosen cannot be used).