Skip to content

Tap30/hiss-spring-boot-mongo-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hiss Spring Boot Mongo Starter build status

An small library which uses Spring Boot autoconfiguration capability that integrates Hiss with Spring Boot and Spring Data Mongo.

By integrating Hiss with Spring Boot project we mean registration of:

  • Hiss bean using HissPropertiesFromEnvProvider
  • Mongo interceptor which automatically encrypts objects before saving to DB and decrypts them after loading.

Quick Start

1. Add Hiss dependency

Apache Maven:

<dependency>
    <groupId>io.github.tap30</groupId>
    <artifactId>hiss-spring-boot-mongo-starter</artifactId>
    <version>0.9.8</version>
</dependency>

Gradle (Groovy):

implementation 'io.github.tap30:hiss-spring-boot-mongo-starter:0.9.8'

Gradle (Kotlin):

implementation("io.github.tap30:hiss-spring-boot-mongo-starter:0.9.8")

2. Set environment variables

HISS_KEYS_A=AAAAAAAAAAAAAAAAAAAAAA==
HISS_KEYS_B=AAAAAAAAAAAAAAAAAAAAAA==
# other keys...
HISS_DEFAULT_ENCRYPTION_KEY_ID=a
HISS_DEFAULT_ENCRYPTION_ALGORITHM=aes-128-gcm
HISS_DEFAULT_HASHING_KEY_ID=b
HISS_DEFAULT_HASHING_ALGORITHM=hmac-sha256

For more information about envs see this.

3. Annotate your class with @Encrypted

import io.github.tap30.Encrypted;

public class User {
    @Encrypted
    private String phoneNumber;
    private String hashedPhoneNumber;

    // getters and setters
}

Note: Getters and setters must exist as Hiss use them to get/set values.

Using custom HissPropertiesProvider

By implementing HissPropertiesProvider and annotating it with @Component this library will pick your implementation rather than default HissPropertiesFromEnvProvider.

Querying Data

Currently there is not easy way to support querying encrypted fields.

To query data, inject Hiss bean (@Autowired Hiss hiss) and use Hiss$hash(String) method to generate hash of content; then pass it to the queries which use hashed fields.

About

Integrates Hiss library with Spring data mongo

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages