Skip to content

Commit d996c2a

Browse files
committed
Remove unsafe/deprecated Encryptors.querableText(CharSequence,CharSequence)
This method is insecure. Users should instead encrypt with their database. Closes gh-8980
1 parent 088ebe2 commit d996c2a

File tree

4 files changed

+5
-51
lines changed

4 files changed

+5
-51
lines changed

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,6 @@ public static TextEncryptor text(CharSequence password, CharSequence salt) {
9191
return new HexEncodingTextEncryptor(standard(password, salt));
9292
}
9393

94-
/**
95-
* Creates an encryptor for queryable text strings that uses standard password-based
96-
* encryption. Uses a 16-byte all-zero initialization vector so encrypting the same
97-
* data results in the same encryption result. This is done to allow encrypted data to
98-
* be queried against. Encrypted text is hex-encoded.
99-
* @param password the password used to generate the encryptor's secret key; should
100-
* not be shared
101-
* @param salt a hex-encoded, random, site-global salt value to use to generate the
102-
* secret key
103-
* @deprecated This encryptor is not secure. Instead, look to your data store for a
104-
* mechanism to query encrypted data.
105-
*/
106-
@Deprecated
107-
public static TextEncryptor queryableText(CharSequence password, CharSequence salt) {
108-
return new HexEncodingTextEncryptor(new AesBytesEncryptor(password.toString(), salt));
109-
}
110-
11194
/**
11295
* Creates a text encryptor that performs no encryption. Useful for developer testing
11396
* environments where working with plain text strings is desired for simplicity.

crypto/src/test/java/org/springframework/security/crypto/encrypt/EncryptorsTests.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,6 @@ public void text() {
6666
assertThat(result.equals(encryptor.encrypt("text"))).isFalse();
6767
}
6868

69-
@Test
70-
public void queryableText() {
71-
CryptoAssumptions.assumeCBCJCE();
72-
TextEncryptor encryptor = Encryptors.queryableText("password", "5c0744940b5c369b");
73-
String result = encryptor.encrypt("text");
74-
assertThat(result).isNotNull();
75-
assertThat(result.equals("text")).isFalse();
76-
assertThat(encryptor.decrypt(result)).isEqualTo("text");
77-
assertThat(result.equals(encryptor.encrypt("text"))).isTrue();
78-
}
79-
8069
@Test
8170
public void noOpText() {
8271
TextEncryptor encryptor = Encryptors.noOpText();

docs/modules/ROOT/pages/features/integrations/cryptography.adoc

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -90,29 +90,6 @@ Encryptors.text("password", "salt")
9090
A `TextEncryptor` uses a standard `BytesEncryptor` to encrypt text data.
9191
Encrypted results are returned as hex-encoded strings for easy storage on the filesystem or in a database.
9292

93-
You can use the `Encryptors.queryableText` factory method to construct a "`queryable`" `TextEncryptor`:
94-
95-
.Queryable TextEncryptor
96-
====
97-
.Java
98-
[source,java,role="primary"]
99-
----
100-
Encryptors.queryableText("password", "salt");
101-
----
102-
103-
.Kotlin
104-
[source,kotlin,role="secondary"]
105-
----
106-
Encryptors.queryableText("password", "salt")
107-
----
108-
====
109-
110-
The difference between a queryable `TextEncryptor` and a standard `TextEncryptor` has to do with initialization vector (IV) handling.
111-
The IV used in a queryable `TextEncryptor.encrypt` operation is shared, or constant, and is not randomly generated.
112-
This means the same text encrypted multiple times always produces the same encryption result.
113-
This is less secure but necessary for encrypted data that needs to be queried against.
114-
An example of queryable encrypted text would be an OAuth `apiKey`.
115-
11693
[[spring-security-crypto-keygenerators]]
11794
== Key Generators
11895
The {security-api-url}org/springframework/security/crypto/keygen/KeyGenerators.html[`KeyGenerators`] class provides a number of convenience factory methods for constructing different types of key generators.

docs/modules/ROOT/pages/whats-new.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@
33

44
Spring Security 6.0 provides a number of new features.
55
Below are the highlights of the release.
6+
7+
== Breaking Changes
8+
9+
* https://github.com/spring-projects/spring-security/issues/8980[gh-8980] - Remove unsafe/deprecated `Encryptors.querableText(CharSequence,CharSequence)`.
10+
Instead use data storage to encrypt values.

0 commit comments

Comments
 (0)