https://github.com/tap30/hiss-spring-boot-jpa-starter
Integrates Hiss library with Spring data JPA
https://github.com/tap30/hiss-spring-boot-jpa-starter
Last synced: about 1 month ago
JSON representation
Integrates Hiss library with Spring data JPA
- Host: GitHub
- URL: https://github.com/tap30/hiss-spring-boot-jpa-starter
- Owner: Tap30
- Created: 2024-06-10T14:23:07.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-16T08:55:41.000Z (about 2 years ago)
- Last Synced: 2026-06-19T05:32:03.290Z (about 2 months ago)
- Language: Java
- Size: 68.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Hiss Spring Boot JPA Starter [](https://github.com/Tap30/hiss-spring-boot-jpa-starter/actions/workflows/build.yml)
An small library which uses Spring Boot autoconfiguration capability that integrates Hiss with Spring Boot and Spring Data JPA.
By integrating Hiss with Spring Boot project we mean registration of:
- Hiss bean using `HissPropertiesFromEnvProvider`
- JPA interceptor which automatically encrypts objects before saving to DB and decrypts them after loading.
## Quick Start
### 1. Add Hiss dependency
Apache Maven:
```xml
io.github.tap30
hiss-spring-boot-jpa-starter
0.9.0
```
Gradle (Groovy):
```groovy
implementation 'io.github.tap30:hiss-spring-boot-jpa-starter:0.9.0'
```
Gradle (Kotlin):
```kotlin
implementation("io.github.tap30:hiss-spring-boot-jpa-starter:0.9.0")
```
### 2. Set environment variables
```bash
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](https://github.com/Tap30/hiss?tab=readme-ov-file#hisspropertiesfromenvprovider).
### 3. Annotate your class with `@EntityListeners(value = {HissJpaEventListener.class})` and the fields you want to encrypt with `@Encrypted`
```java
import io.github.tap30.Encrypted;
@EntityListeners(value = {HissJpaEventListener.class})
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.