Skip to content

Commit bde4235

Browse files
committed
Update Encryptors documentation
Fixes gh-8208
1 parent 78d8b9f commit bde4235

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

crypto/src/main/java/org/springframework/security/crypto/encrypt/Encryptors.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ public class Encryptors {
3939
* not be shared
4040
* @param salt a hex-encoded, random, site-global salt value to use to generate the
4141
* key
42-
*
43-
* @see #standard(CharSequence, CharSequence) which uses the slightly weaker CBC mode
44-
* (instead of GCM)
4542
*/
4643
public static BytesEncryptor stronger(CharSequence password, CharSequence salt) {
4744
return new AesBytesEncryptor(password.toString(), salt,
@@ -55,11 +52,19 @@ public static BytesEncryptor stronger(CharSequence password, CharSequence salt)
5552
* provided salt is expected to be hex-encoded; it should be random and at least 8
5653
* bytes in length. Also applies a random 16 byte initialization vector to ensure each
5754
* encrypted message will be unique. Requires Java 6.
55+
* NOTE: This mode is not
56+
* <a href="https://en.wikipedia.org/wiki/Authenticated_encryption">authenticated</a>
57+
* and does not provide any guarantees about the authenticity of the data.
58+
* For a more secure alternative, users should prefer
59+
* {@link #stronger(CharSequence, CharSequence)}.
5860
*
5961
* @param password the password used to generate the encryptor's secret key; should
6062
* not be shared
6163
* @param salt a hex-encoded, random, site-global salt value to use to generate the
6264
* key
65+
*
66+
* @see #stronger(CharSequence, CharSequence) which uses the significatly more secure
67+
* GCM (instead of CBC)
6368
*/
6469
public static BytesEncryptor standard(CharSequence password, CharSequence salt) {
6570
return new AesBytesEncryptor(password.toString(), salt,

docs/manual/src/docs/asciidoc/index.adoc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6671,14 +6671,17 @@ The Encryptors class provides factory methods for constructing symmetric encrypt
66716671

66726672
[[spring-security-crypto-encryption-bytes]]
66736673
==== BytesEncryptor
6674-
Use the Encryptors.standard factory method to construct a "standard" BytesEncryptor:
6674+
Use the `Encryptors.stronger` factory method to construct a BytesEncryptor:
66756675

66766676
[source,java]
66776677
----
6678-
Encryptors.standard("password", "salt");
6678+
Encryptors.stronger("password", "salt");
66796679
----
66806680

6681-
The "standard" encryption method is 256-bit AES using PKCS #5's PBKDF2 (Password-Based Key Derivation Function #2). This method requires Java 6. The password used to generate the SecretKey should be kept in a secure place and not be shared. The salt is used to prevent dictionary attacks against the key in the event your encrypted data is compromised. A 16-byte random initialization vector is also applied so each encrypted message is unique.
6681+
The "stronger" encryption method creates an encryptor using 256 bit AES encryption with
6682+
Galois Counter Mode (GCM).
6683+
It derives the secret key using PKCS #5's PBKDF2 (Password-Based Key Derivation Function #2).
6684+
This method requires Java 6. The password used to generate the SecretKey should be kept in a secure place and not be shared. The salt is used to prevent dictionary attacks against the key in the event your encrypted data is compromised. A 16-byte random initialization vector is also applied so each encrypted message is unique.
66826685

66836686
The provided salt should be in hex-encoded String form, be random, and be at least 8 bytes in length. Such a salt may be generated using a KeyGenerator:
66846687

@@ -6687,6 +6690,11 @@ The provided salt should be in hex-encoded String form, be random, and be at lea
66876690
String salt = KeyGenerators.string().generateKey(); // generates a random 8-byte salt that is then hex-encoded
66886691
----
66896692

6693+
Users may also use the `standard` encryption method, which is 256-bit AES in Cipher Block Chaining (CBC) Mode.
6694+
This mode is not https://en.wikipedia.org/wiki/Authenticated_encryption[authenticated] and does not provide any
6695+
guarantees about the authenticity of the data.
6696+
For a more secure alternative, users should prefer `Encryptors.stronger`.
6697+
66906698
[[spring-security-crypto-encryption-text]]
66916699
==== TextEncryptor
66926700
Use the Encryptors.text factory method to construct a standard TextEncryptor:

0 commit comments

Comments
 (0)