Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/transempiric/simple-encryptor
Simple property ecryptor/decryptor extension for Spring Framework (RSA Public and Private PEM keys and the like).
https://github.com/transempiric/simple-encryptor
encryption-support encryptor rsa rsa-cryptography rsa-encryption rsa-key rsa-key-encryption spring spring-boot spring-cloud spring-framework spring-security spring-security-rsa springframework
Last synced: about 1 month ago
JSON representation
Simple property ecryptor/decryptor extension for Spring Framework (RSA Public and Private PEM keys and the like).
- Host: GitHub
- URL: https://github.com/transempiric/simple-encryptor
- Owner: TransEmpiric
- License: mit
- Created: 2018-02-23T16:18:36.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-02-26T19:46:04.000Z (over 6 years ago)
- Last Synced: 2024-10-11T16:05:05.280Z (about 1 month ago)
- Topics: encryption-support, encryptor, rsa, rsa-cryptography, rsa-encryption, rsa-key, rsa-key-encryption, spring, spring-boot, spring-cloud, spring-framework, spring-security, spring-security-rsa, springframework
- Language: Java
- Size: 14.6 KB
- Stars: 8
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# simple-encryptor
Spring Framework encryption extension.
SimpleEncryptor supports property encryption via TextEncryptor, with optional use of [spring-security-rsa](https://github.com/dsyer/spring-security-rsa) RSA (PUBLIC and PRIVATE keys).
RSA (PUBLIC and PRIVATE keys) can be deleted or cleared after TextEncryptor instantiation using the SimpleEncryptorFactoryBean.SimpleEncryptor provides encryption support for property sources in Spring Boot Applications and plain old Spring.
## How to get use.
1. Add the simple-encryptor dependency to your project (Maven Central):
```groovy
compile("com.transempiric:simple-encryptor:1.0.0")
```
```xml
com.transempiric
simple-encryptor
1.0.0
compile
```
2. Spring Boot property example:
```java
@SpringBootApplication
public class WebTemplateApplication {
public static void main(String[] args) throws Exception {
TextEncryptor rsaDecryptor = new SimpleEncryptorFactoryBean()
.rsaDecryptor("classPath:local_enc_private_key.pem")
.createInstance();
//TODO: Clean up and make use of the SimpleEncryptorFactoryBean.
SimpleEncryptorPropertyResolver resolver = new SimpleEncryptorPropertyResolver(rsaDecryptor);
SimpleEncryptorEnvironment env = new SimpleEncryptorEnvironment(SimpleEncryptorInterceptionMode.WRAPPER, resolver);
new SpringApplicationBuilder()
.environment(env)
.sources(WebTemplateApplication.class)
.run(args);
}
}
```
Encryptable properties will be enabled across the entire Spring Environment (This means any system property, environment property, command line argument, application.properties, yaml properties, and any other custom property sources can contain encrypted properties)2. Spring Bean example for encryptors:
```java
import com.transempiric.simpleEncryptor.SimpleEncryptorFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.encrypt.TextEncryptor;
import static com.transempiric.simpleEncryptor.SimpleEncryptorFactoryBean.SIMPLE_ENCRYPTOR_SALT_PROPERTY_NAME;
import static com.transempiric.simpleEncryptor.SimpleEncryptorFactoryBean.SIMPLE_ENCRYPTOR_SECRET_PROPERTY_NAME;
@Configuration
public class SimpleEncryptorConfigExample {
@Bean
public TextEncryptor rsaSimpleEncryptor() throws Exception {
return new SimpleEncryptorFactoryBean()
.rsaEncryptor("classPath:local_enc_public_key.pem")
// .clearKeyFileContents(false)
// .deleteKeyFiles(false)
.createInstance();
}
@Bean
public TextEncryptor rsaSimpleDecryptor() throws Exception {
return new SimpleEncryptorFactoryBean()
.rsaDecryptor("classPath:local_enc_private_key.pem")
// .clearKeyFileContents(true)
// .deleteKeyFiles(true)
.createInstance();
}
// Required (Hex-encoded string): Inject System property -Dsimple.encryptor.secret=497349744150726F626C656D466F72596F75546F41736B
// Optional (Hex-encoded string): Inject System property -Dsimple.encryptor.salt=456E63727970746F7273
@Bean
public TextEncryptor hexEncodingSimpleEncryptor() throws Exception {
return new SimpleEncryptorFactoryBean()
.hexEncodingTextEncryptor(
System.getProperty(SIMPLE_ENCRYPTOR_SECRET_PROPERTY_NAME),
System.getProperty(SIMPLE_ENCRYPTOR_SALT_PROPERTY_NAME)
)
.createInstance();
}
@Bean
public String spaceMonkey(
TextEncryptor hexEncodingSimpleEncryptor,
TextEncryptor rsaSimpleEncryptor,
TextEncryptor rsaSimpleDecryptor
) {
/*
System.out.println("**************** SimpleEncryptorConfigExample Test *************************");
System.out.println(rsaSimpleEncryptor.encrypt("rupertDurden"));
System.out.println(rsaSimpleEncryptor.encrypt("rupertDurden"));
System.out.println(rsaSimpleDecryptor.decrypt(rsaSimpleEncryptor.encrypt("rupert")));
System.out.println(rsaSimpleDecryptor.decrypt(rsaSimpleEncryptor.encrypt("durden")));
System.out.println(hexEncodingSimpleEncryptor.encrypt("rupert"));
System.out.println(hexEncodingSimpleEncryptor.encrypt("durden"));
System.out.println(hexEncodingSimpleEncryptor.decrypt(hexEncodingSimpleEncryptor.encrypt("rupert")));
System.out.println(hexEncodingSimpleEncryptor.decrypt(hexEncodingSimpleEncryptor.encrypt("durden")));
System.out.println("**************** SimpleEncryptorConfigExample Test *************************");
*/
return "SpaceMonkey";
}
}
```
## Major Props to some Spring peeps
[Dave Syer](https://github.com/dsyer/spring-security-rsa) for [spring-security-rsa](https://github.com/dsyer/spring-security-rsa) and [spring-cloud-config](https://github.com/spring-cloud/spring-cloud-config).
[Ulises Bocchio](https://github.com/ulisesbocchio) for [jasypt-spring-boot](https://github.com/ulisesbocchio/jasypt-spring-boot).