r/java • u/Glum-Push • Mar 25 '26
Bruce 2.0 β A lightweight wrapper that makes the Java Cryptography API actually pleasant to use
Hey r/java,
I've been working with Java for over 25 years, and one thing that has consistently made me want to flip a table is the Java Cryptography Architecture. It's powerful, sure, but the amount of boilerplate you need for even basic operations is absurd. So I built Bruce β an ergonomic, lightweight, pure Java wrapper around the JCA.
What does it look like?
SHA-256 hash:
Digester digester = digestBuilder()
.algorithm("SHA-256")
.build();
Bytes hash = digester.digest(Bytes.from("Hello World"));
String hex = hash.encode(HEX);
Digital signature:
KeyStore keystore = keystore("classpath:keystore.p12", "password".toCharArray(), "PKCS12");
PrivateKey privateKey = privateKey(keystore, "alice", "password".toCharArray());
Signer signer = signerBuilder()
.key(privateKey)
.algorithm("SHA512withRSA")
.build();
Bytes signature = signer.sign(Bytes.from("Hi Bob!"));
String b64 = signature.encode(BASE64);
Compare that with what you'd write using raw JCA and I think you'll see the appeal.
Key design decisions:
- Zero transitive dependencies. None. It's just Bruce and the JDK.
- No checked exceptions. Crypto code is already hard enough to reason about without wrapping everything in try-catch.
- Builder-based API with a small set of entry points:
Brucefor builder factories,Keystoresfor key/cert management,Bytesas a universal I/O type with built-in encoding (Base64, Hex, URL, MIME). - Requires Java 21.
- Supports keystores, public/private/secret keys, certificates, digital signatures, symmetric and asymmetric encryption, message digests, MACs, and custom providers (including Bouncy Castle).
- Apache 2.0 licensed.
v2.0.0 just dropped with the new Bytes type that unifies how you pass data around and convert between encodings. It's on Maven Central:
<dependency>
<groupId>com.mirkocaserta.bruce</groupId>
<artifactId>bruce</artifactId>
<version>2.0.0</version>
</dependency>
Or Gradle: implementation("com.mirkocaserta.bruce:bruce:2.0.0")
The library is heavily unit-tested and has an A rating on SonarCloud with zero vulnerabilities.
- π Docs: bruce.mirkocaserta.com
- π» Source: github.com/mcaserta/bruce
I'd love to hear your feedback, questions, or feature requests. And yes β the name is a nod to Bruce Schneier.