Introduction

Fernet for Java is a lightweight, open-source implementation of the Fernet specification. It enables developers to generate, encrypt, and validate secure tokens with symmetric encryption, ensuring confidentiality and integrity in distributed systems.

With key rotation support, the library allows seamless migration between encryption keys without downtime, reducing the blast radius of potential key compromise.

Key Features

  • AES-128 CBC encryption for confidentiality
  • HMAC-SHA256 verification for integrity
  • Token expiration support for secure session handling
  • Key rotation mechanism with versioned keys and backward compatibility
  • Lightweight design with minimal dependencies
  • MIT License for open collaboration

Getting Started

<dependency>
  <groupId>dev.ercan</groupId>
  <artifactId>fernet</artifactId>
  <version>1.0.0</version>
</dependency>

Quick Start Example

import dev.ercan.fernet.Fernet;
String key = secretManager.get("fernet-key");

Fernet fernet = Fernet.of(key);

String token = fernet.encryptUtf8("secret message");
String message = fernet.decryptUtf8(token);

Use Cases

  • Secure API request validation
  • Authentication flows
  • Session management in microservices
  • Protecting sensitive payloads in distributed systems
  • Key rotation for compliance with PCI DSS, HIPAA, and security best practices

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! Please open issues or submit pull requests via GitHub.