https://github.com/codesqueak/jackson-json-crypto
Jackson Crypto Extension Module
https://github.com/codesqueak/jackson-json-crypto
aes encryption jackson java json module
Last synced: 7 months ago
JSON representation
Jackson Crypto Extension Module
- Host: GitHub
- URL: https://github.com/codesqueak/jackson-json-crypto
- Owner: codesqueak
- License: mit
- Created: 2017-12-28T20:11:48.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-01-25T09:41:14.000Z (over 3 years ago)
- Last Synced: 2023-08-05T11:13:41.342Z (almost 2 years ago)
- Topics: aes, encryption, jackson, java, json, module
- Language: Java
- Homepage:
- Size: 217 KB
- Stars: 20
- Watchers: 4
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README


[](https://search.maven.org/search?q=g:%22com.codingrodent%22%20AND%20a:%22jackson-json-crypto%22)# Jackson JSON Crypto Module
A Jackson module to support JSON encryption and decryption operations. Encryption is via AES. Key generation is password
based.Keyword: Jackson, JSON, AES, PKCS5, Encryption, Salt, Initialization Vector, IV, Java
Based on an idea from [meltmedia](https://github.com/meltmedia/jackson-crypto)
If you find this project useful, you may want to [__Buy me a Coffee!__ :coffee:](https://www.buymeacoffee.com/codesqueak) Thanks :thumbsup:
## Build
Windows
```
gradlew clean build test
```Linux
```
./gradlew clean build test
```
## How to useThese examples are demonstrated in the ```CryptoDemo``` unit test class
### Option 1 - Very Quick and Easy
Add the crypto module to your project. Common use case with a cipher of AES/CBC/PKCS5Padding and a key factory algorithm of PBKDF2WithHmacSHA512
Just supply a password.
```java
ObjectMapper objectMapper = EncryptionService.getInstance("Password1");
```### Option 2 - Quick and Easy
Similar to Option 1, but you already have a ObjectMapper
```java
ObjectMapper objectMapper = ...
EncryptionService encryptionService =
new EncryptionService(objectMapper, new PasswordCryptoContext("Password1");
objectMapper.registerModule(new CryptoModule().addEncryptionService(encryptionService));
```### Option 3 - Configure Everything
Where you just need full control.
```java
// get an object mapper
ObjectMapper objectMapper = new ObjectMapper();
// set up a custom crypto context - Defines the interface to the crypto algorithms used
ICryptoContext cryptoContext = new PasswordCryptoContext("Password");
// The encryption service holds functionality to map clear to / from encrypted JSON
EncryptionService encryptionService = new EncryptionService(objectMapper, cryptoContext);
// Create a Jackson module and tell it about the encryption service
CryptoModule cryptoModule = new CryptoModule().addEncryptionService(encryptionService);
// Tell Jackson about the new module
objectMapper.registerModule(cryptoModule);
```### Encrypt a field
Any field that is required to be encrypted has to be marked as such. This can be done by either annotating the getter() or
by annotating the field definition.This ...
```java
private String critical;
...
@JsonProperty
@Encrypt
public String getCritical() {
return this.critical;
}
```... or ...
```java
@JsonProperty
@Encrypt
private String critical;
```## Output JSON Format
```json
{
"critical":{
"salt":"IRqsz99no75sx9SCGrzOSEdoMVw=",
"iv":"bfKvxBhq7X5su9VtvDdOGQ==",
"value":"pXWsFPzCnmPieitbGfkvofeQE3fj0Kb4mSP7e28+Jc0="
}
}
```## Using Jenkins
The project includes a Jenkins file to control a pipeline build.
## Include Using Maven
```com.codingrodent
jackson-json-crypto
2.2.0```
## Include Using Gradle
```
compile group: 'com.codingrodent', name: 'jackson-json-crypto', version: '2.2.0'
```