Skip to content

Commit d2b859a

Browse files
add encryption and description in Spring example
1 parent 6dcc775 commit d2b859a

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@
189189
<scope>test</scope>
190190
</dependency>
191191

192+
<dependency>
193+
<groupId>org.springframework.security</groupId>
194+
<artifactId>spring-security-crypto</artifactId>
195+
<version>6.3.1</version>
196+
</dependency>
197+
192198
</dependencies>
193199

194200

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package encryption;
2+
3+
import org.springframework.security.crypto.keygen.BytesKeyGenerator;
4+
import org.springframework.security.crypto.keygen.KeyGenerators;
5+
6+
public class SpringSecurityCryptoModule {
7+
/**
8+
* Reference: https://docs.spring.io/spring-security/site/docs/3.1.x/reference/crypto.html
9+
*/
10+
public static void main(String... args) {
11+
// BytesEncryptor encryptor = Encryptors.standard("password", "salt");
12+
13+
String salt = KeyGenerators.string().generateKey(); // generates a random 8-byte salt that is then hex-encoded
14+
System.out.println("salt is: " + salt);
15+
16+
// TextEncryptor textEncryptor = Encryptors.text("password", "salt");
17+
18+
BytesKeyGenerator generator = KeyGenerators.secureRandom();
19+
byte[] key = generator.generateKey();
20+
System.out.println("key is: " + key);
21+
22+
}
23+
}

0 commit comments

Comments
 (0)