Skip to content

Commit 01f8eb3

Browse files
committed
Update Encryptors documentation
Fixes gh-8208
1 parent a9a9c2c commit 01f8eb3

File tree

2 files changed

+18
-6
lines changed
  • crypto/src/main/java/org/springframework/security/crypto/encrypt
  • docs/manual/src/docs/asciidoc/_includes/servlet/crypto

2 files changed

+18
-6
lines changed

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

+8-3
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/_includes/servlet/crypto/index.adoc

+10-3
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ Encryptors are thread-safe.
1717

1818
[[spring-security-crypto-encryption-bytes]]
1919
=== BytesEncryptor
20-
Use the Encryptors.standard factory method to construct a "standard" BytesEncryptor:
20+
Use the `Encryptors.stronger` factory method to construct a BytesEncryptor:
2121

2222
[source,java]
2323
----
24-
Encryptors.standard("password", "salt");
24+
Encryptors.stronger("password", "salt");
2525
----
2626

27-
The "standard" encryption method is 256-bit AES using PKCS #5's PBKDF2 (Password-Based Key Derivation Function #2).
27+
The "stronger" encryption method creates an encryptor using 256 bit AES encryption with
28+
Galois Counter Mode (GCM).
29+
It derives the secret key using PKCS #5's PBKDF2 (Password-Based Key Derivation Function #2).
2830
This method requires Java 6.
2931
The password used to generate the SecretKey should be kept in a secure place and not be shared.
3032
The salt is used to prevent dictionary attacks against the key in the event your encrypted data is compromised.
@@ -38,6 +40,11 @@ Such a salt may be generated using a KeyGenerator:
3840
String salt = KeyGenerators.string().generateKey(); // generates a random 8-byte salt that is then hex-encoded
3941
----
4042

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

0 commit comments

Comments
 (0)