Question

Background: I am using the PBEWITHSHA256AND128BITAES-CBC-BC algorithm (Bouncy Castle) with Jasypt via the Grails plugin. Configuration is straightforward:

jasypt {
    algorithm = "PBEWITHSHA256AND256BITAES-CBC-BC"
    providerName = "BC"
    password = "<your very secret passphrase>"
    keyObtentionIterations = 1000
}

I would like to know how to choose a secure password for the above. Are there real or practical limits on length, restricted characters, etc? A specific generator I should be using? I couldn't find clear documentation on this and all examples use something like the above (e.g., "password", "secret" etc.).

Was it helpful?

Solution

Password-based encryption takes a password, as the term implies. Passwords are run through a key derivation function to obtain the actual key. As a KDF is typically constructed from a hash function, the password may be of any length and contain any characters.

Passwords have to be run through a KDF because typical passwords don't contain anywhere near enough entropy to be considered secure against brute force attacks. A KDF substitutes this lack of "key space" depth with computationally expensive key derivation – hence the thousands of iterations. The disadvantage is the fact that initializing the cipher is also expensive.

This is a tradeoff well worth it if passwords are required instead of raw keys. However, in your case it would be a better idea to use the raw key. Unfortunately it seems that the Jasypt library you are using only supports PBE.

To contain at least 256 bits of entropy (as much as a raw random 256-bit key), the password has to contain at least 43 random (case-sensitive) alphanumeric characters. If you pick a password that long, you can probably lower the iteration count to 1.

It seems pretty odd to me that you have to think through all this even though you are using a library that you are supposed to be able to use "without the need of having deep knowledge on how cryptography works". Why does it expose all the ugly details if users aren't supposed to know what they are?

OTHER TIPS

For generating a secure passphrase, have a look at the Diceware site. Note that you have to do the work by hand and not use a computer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top