PEM encoding/decoding
Encode and decode PEM-formatted cryptographic objects natively.
Porównanie kodu
✕ Java 8
String pem = "-----BEGIN CERTIFICATE-----\n"
+ Base64.getMimeEncoder()
.encodeToString(
cert.getEncoded())
+ "\n-----END CERTIFICATE-----";
✓ Java 25 (Preview)
// Encode to PEM
String pem = PEMEncoder.of()
.encodeToString(cert);
// Decode from PEM
var cert = PEMDecoder.of()
.decode(pemString);
Widzisz problem z tym kodem? Daj nam znać.
Dlaczego nowoczesne podejście wygrywa
No manual Base64
PEM headers, line wrapping, and Base64 handled automatically.
Bidirectional
Encode to PEM and decode from PEM with one API.
Standard format
Produces RFC 7468-compliant PEM output.
Stare podejście
Manual Base64 + Headers
Nowoczesne podejście
PEM API
Od JDK
25
Poziom trudności
Zaawansowany
Wsparcie JDK
PEM encoding/decoding
Preview
Preview in JDK 25 (JEP 470). Requires --enable-preview.
Jak to działa
The PEM API provides standard encoding/decoding for certificates, keys, and other cryptographic objects in PEM format. No more manual Base64 wrapping with BEGIN/END headers.
Powiązana dokumentacja