* @return the public salt that should be used to compute a hash based on the specified request or
* {@code null} if no public salt should be used.
*/
protected ByteSource getPublicSalt(HashRequest request) {
ByteSource publicSalt = request.getSalt();
if (publicSalt != null && !publicSalt.isEmpty()) {
//a public salt was explicitly requested to be used - go ahead and use it:
return publicSalt;
}
publicSalt = null;
//check to see if we need to generate one:
ByteSource privateSalt = getPrivateSalt();
boolean privateSaltExists = privateSalt != null && !privateSalt.isEmpty();
//If a private salt exists, we must generate a public salt to protect the integrity of the private salt.
//Or generate it if the instance is explicitly configured to do so:
if (privateSaltExists || isGeneratePublicSalt()) {
publicSalt = getRandomNumberGenerator().nextBytes();