Add pem-api module: PEMDecoder/PEMEncoder (JEP 538 preview on JDK 27, JEP 542 final in JDK 28) for JWT keys, TLS, encrypted keys and BouncyCastle migration

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CifR2BE7PBvRy5hT8TS9oz
This commit is contained in:
2026-10-26 01:50:05 +00:00
co-authored by Claude Sonnet 5.5
parent c3cc57f482
commit 2e25042a68
34 changed files with 895 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
$ java --enable-preview -cp ... Failures (27.0.1.0.2+1)
== the file holds a different kind of object than the class you asked for
certificate as PublicKey !! java.lang.ClassCastException: Cannot cast sun.security.x509.X509CertImpl to java.security.PublicKey
private key as PublicKey !! java.lang.ClassCastException: Cannot cast sun.security.rsa.RSAPrivateCrtKeyImpl to java.security.PublicKey
RSA private key as KeyPair !! java.lang.ClassCastException: Cannot cast sun.security.rsa.RSAPrivateCrtKeyImpl to java.security.KeyPair
== untyped decode: the result type depends on what the file contains
RSA PKCS#8 -> PrivateKey RSA
EC PKCS#8 (openssl embeds the public key) -> KeyPair
EC PKCS#8, asked for PrivateKey -> PrivateKey EC
EC PKCS#8, asked for KeyPair -> KeyPair
== the old OpenSSL formats
RSA PRIVATE KEY (PKCS#1) -> PrivateKey RSA
EC PRIVATE KEY (SEC1), untyped -> PEM(type=EC PRIVATE KEY) - NOT decoded
EC PRIVATE KEY (SEC1), asked for PrivateKey !! java.lang.ClassCastException: Cannot cast java.security.PEM to java.security.PrivateKey
as a PEM object: type=EC PRIVATE KEY, decoded bytes=121
== malformed text
empty string !! java.lang.IllegalArgumentException: java.io.EOFException: No data available
no PEM in the text !! java.lang.IllegalArgumentException: java.io.EOFException: No PEM data found
footer missing !! java.lang.IllegalArgumentException: java.io.EOFException: Incomplete header
body is not Base64 of a key !! java.lang.IllegalArgumentException: java.io.IOException: No recognized algorithm detected in encoding
Windows line endings (CRLF) -> PublicKey RSA
comment lines before the header -> PublicKey RSA
== several objects in one string: only the first is returned
decode(String) on a 2-certificate bundle -> CN=localhost
exit=0