Transparent field-level format-preserving encryption for Hibernate. Annotate a field, data is protected on write and accessed on read. Zero boilerplate.
Built on io.cyphera:cyphera from Maven Central.
Add the dependency:
<dependency>
<groupId>io.cyphera</groupId>
<artifactId>cyphera-hibernate</artifactId>
<version>VERSION</version>
</dependency>Add cyphera.json to your classpath or /etc/cyphera/cyphera.json. Annotate your fields:
@Entity
public class Customer {
@Id
private Long id;
private String name;
@CypheraProtect("ssn")
private String ssn;
@CypheraProtect("credit_card")
private String creditCard;
}That's it. The Hibernate Integrator auto-discovers @CypheraProtect fields at boot. No converter classes, no config classes, no wiring.
- INSERT/UPDATE:
ssn→T01i6J-xF-07pXin the database - SELECT:
T01i6J-xF-07pX→123-45-6789back to the entity - Your code only sees plaintext. The database only sees ciphertext.
mvn package -DskipTests- Add the Maven dependency
- Place
cyphera.jsonon classpath or at/etc/cyphera/cyphera.json(or setCYPHERA_CONFIGURATION_FILEenv var) - Annotate fields with
@CypheraProtect("configuration_name") - Done — the Integrator handles the rest via
META-INF/servicesauto-discovery
Headers add 3 characters. Ensure your columns have room: existing width + 3. Or set header_enabled: false in the configuration for same-length output.
- Boot:
CypheraIntegratorauto-discovered viaMETA-INF/services. Registers event listeners. - Scan: On first access, scans entity fields for
@CypheraProtectand caches field→configuration mapping. - Write: PreInsert/PreUpdate modify the Hibernate state array — database gets ciphertext, entity keeps plaintext.
- Read: PostLoad decrypts fields on the entity after loading.
- SDK:
CypheraHolderauto-discoverscyphera.jsonif not explicitly configured.
@Type(value = CypheraType.class, parameters = @Parameter(name = "configuration", value = "ssn"))
private String ssn;@Converter
public class SsnConverter extends io.cyphera.hibernate.compat.CypheraConverter {
public SsnConverter() { super("ssn"); }
}- Auto-discover:
CYPHERA_CONFIGURATION_FILEenv →./cyphera.json→/etc/cyphera/cyphera.json - Explicit:
CypheraHolder.set(Cyphera.fromFile("path"))at bootstrap - Spring Boot: auto-config handles it (if cyphera-spring is also on classpath)
- "Unknown configuration" —
@CypheraProtect("...")doesn't matchcyphera.json - Integrator not loading — check
META-INF/servicesis in the JAR - No configuration file — ensure
cyphera.jsonexists at one of the auto-discover locations
{
"configurations": {
"ssn": { "engine": "ff1", "key_ref": "my-key", "header": "T01" },
"credit_card": { "engine": "ff1", "key_ref": "my-key", "header": "T02" }
},
"keys": {
"my-key": { "material": "2B7E151628AED2A6ABF7158809CF4F3C" }
}
}- SPI extension points: custom ConfigurationResolver, FieldProcessor, MetadataResolver
- Spring Boot auto-configuration for CypheraHolder
- Hibernate 5
@TypeDefcompatibility - Audit logging integration
Apache 2.0 — Copyright 2026 Horizon Digital Engineering LLC