com.codingrodent.jackson.crypto

A Crypto Module for Jackson

License

License

Categories

Categories

JSON Data Jackson
GroupId

GroupId

com.codingrodent.jackson.crypto
ArtifactId

ArtifactId

jackson-json-crypto
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

com.codingrodent.jackson.crypto
A Crypto Module for Jackson
Project URL

Project URL

https://github.com/codesqueak/jackson-json-crypto
Source Code Management

Source Code Management

https://github.com/codesqueak/jackson-json-crypto

Download jackson-json-crypto

How to add to project

<!-- https://jarcasting.com/artifacts/com.codingrodent.jackson.crypto/jackson-json-crypto/ -->
<dependency>
    <groupId>com.codingrodent.jackson.crypto</groupId>
    <artifactId>jackson-json-crypto</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.codingrodent.jackson.crypto/jackson-json-crypto/
implementation 'com.codingrodent.jackson.crypto:jackson-json-crypto:0.1.0'
// https://jarcasting.com/artifacts/com.codingrodent.jackson.crypto/jackson-json-crypto/
implementation ("com.codingrodent.jackson.crypto:jackson-json-crypto:0.1.0")
'com.codingrodent.jackson.crypto:jackson-json-crypto:jar:0.1.0'
<dependency org="com.codingrodent.jackson.crypto" name="jackson-json-crypto" rev="0.1.0">
  <artifact name="jackson-json-crypto" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.codingrodent.jackson.crypto', module='jackson-json-crypto', version='0.1.0')
)
libraryDependencies += "com.codingrodent.jackson.crypto" % "jackson-json-crypto" % "0.1.0"
[com.codingrodent.jackson.crypto/jackson-json-crypto "0.1.0"]

Dependencies

compile (6)

Group / Artifact Type Version
com.fasterxml.jackson.core : jackson-core jar 2.9.3
com.fasterxml.jackson.core : jackson-databind jar 2.9.3
com.fasterxml.jackson.core : jackson-annotations jar 2.9.3
org.hibernate : hibernate-validator jar 5.3.0.Final
org.slf4j : slf4j-api jar 1.7.25
javax.el : javax.el-api jar 2.2.5

test (3)

Group / Artifact Type Version
junit : junit jar 4.12
org.mockito : mockito-core jar 2.13.0
org.hamcrest : hamcrest-all jar 1.3

Project Modules

There are no modules declared in this project.

CodeQL Java CI with Gradle Maven Central

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

If you find this project useful, you may want to Buy me a Coffee! โ˜• Thanks ๐Ÿ‘

Build

Windows

gradlew clean build test

Linux

./gradlew clean build test

How to use

These 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.

ObjectMapper objectMapper = EncryptionService.getInstance("Password1");

Option 2 - Quick and Easy

Similar to Option 1, but you already have a ObjectMapper

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.

// 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 ...

    private String critical;
    ...
    @JsonProperty
    @Encrypt
    public String getCritical() {
        return this.critical;
    }

... or ...

    @JsonProperty
    @Encrypt
    private String critical;

Output JSON Format

{  
   "critical":{  
      "salt":"IRqsz99no75sx9SCGrzOSEdoMVw=",
      "iv":"bfKvxBhq7X5su9VtvDdOGQ==",
      "value":"pXWsFPzCnmPieitbGfkvofeQE3fj0Kb4mSP7e28+Jc0="
   }
}

Using Jenkins

The project includes a Jenkins file to control a pipeline build.

Include Using Maven

<dependency>
  <groupId>com.codingrodent</groupId>
  <artifactId>jackson-json-crypto</artifactId>
  <version>2.2.0</version>
</dependency>

Include Using Gradle

compile group: 'com.codingrodent', name: 'jackson-json-crypto', version: '2.2.0'

Versions

Version
0.1.0