项目作者: meltmedia

项目描述 :
Cryptographic utilities for Jackson
高级语言: Java
项目地址: git://github.com/meltmedia/jackson-crypto.git
创建时间: 2014-10-12T02:56:32Z
项目社区:https://github.com/meltmedia/jackson-crypto

开源协议:

下载


Jackson Crypto

Build Status

Cryptographic utilities for Jackson.

Usage

To use this package from Maven, include the following dependency in your project:

  1. <dependency>
  2. <groupId>com.meltmedia.jackson</groupId>
  3. <artifactId>jackson-crypto</artifactId>
  4. <version>0.2.0</version>
  5. </dpendency>

Then create a new CryptoModule and register it with your ObjectMapper.

  1. EncryptionService service = ...;
  2. ObjectMapper mapper = ...;
  3. mapper.registerModule(new CryptoModule().addSource(service));

Once this is done, you can use the @Encrypted annotation on your @JsonProperty annotated methods to encrypt them during serialization and
decrypt them during deserialization. So, a POJO like the following:

  1. public class Pojo {
  2. protected String secret;
  3. @JsonProperty
  4. @Encrypted
  5. public String getSecret() {
  6. return this.secret;
  7. }
  8. public void setSecret( String secret ) {
  9. this.secret = secret;
  10. }
  11. }

will serialize into JSON like:

  1. {
  2. "secret": {
  3. "salt": "tKD8wQ==",
  4. "iv": "s9hTJRaZn6fxxpA4nVfDag==",
  5. "value": "UZENJOltf+9EZS03AXbmeg==",
  6. "cipher": "aes-256-cbc",
  7. "keyDerivation": "pbkdf2",
  8. "keyLength": 256,
  9. "iterations": 2000
  10. }
  11. }

Example

This project does not yet have its own example project, but you can see an example of using this library in the Dropwizard Crypto example project.