Skip to content

feat(jdk27): add demo for JEP 538 - #384

Merged
AloisSeckar merged 3 commits into
AloisSeckar:masterfrom
Akhil-1527:jep538-pem-encodings
Sep 30, 2026
Merged

AloisSeckar merged 3 commits into
AloisSeckar:masterfrom
Akhil-1527:jep538-pem-encodings

Conversation

@Akhil-1527

@Akhil-1527 Akhil-1527 commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #376
Closes #360

Adds PemEncodingsDemo under java27/jep538, with its JSON record and loader registration, and turns the JEP 470 demo into a linking class that points to it, as the issue asks. The JEP 470 JSON record now has link: true, like the other replaced previews.

The demo generates an EC key pair and walks through the main parts of the API:

  • encodes the public key with PEMEncoder and decodes it back with PEMDecoder.decode(text, ECPublicKey.class)
  • encrypts the private key with withEncryption, decrypts it with withDecryption, and shows the new CryptoException for a wrong password
  • encrypts the whole KeyPair with a non-default algorithm through EncryptedPrivateKeyInfo.encrypt, then restores it with getKeyPair
  • uses the PEM class to keep the text before the BEGIN line, and to encode a type that has no Java class (with the new byte[] constructor)
  • switches over the decoded BinaryEncodable to find out what a text holds
Public key as PEM text:
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEuJcEpLvv6MtPpvtDcIOvWILNBR73
BzYnJO4PfO/ukMYSDYku2TP7RzsTkxB6jJdsI5BUihN6hG66Z+AJA2/FAQ==
-----END PUBLIC KEY-----
Decoded public key equals the original: true
Encrypted private key starts with: -----BEGIN ENCRYPTED PRIVATE KEY-----
Decrypted private key equals the original: true
Wrong password: javax.crypto.CryptoException
Key pair restored from one encrypted PEM text: true
PEM type: PUBLIC KEY, leading text: Signing key of the demo service, binary size: 91 bytes
Decoded: EC public key
Decoded: encrypted private key (PBEWithHmacSHA256AndAES_128)
Decoded: PEM of type DEMO NOTE, which has no Java class

The class header lists the changes in JDK 26 and JDK 27. For JDK 27 I compared the API of JDK 26.0.1 and JDK 27 with javap, because the JEP 538 text also lists getKeyPair as new, but it is already in JDK 26.

One thing that surprised me: a private key restored from a KeyPair PEM keeps the public key in its encoding, so equals() with the original key returns false. The demo compares the private value instead and explains why in a comment.

mvn clean install and the full jar run pass locally on JDK 27. As suggested in the review, this PR also adds the JEP 524 linking class under java26/jep524, with its JSON record and loader registration, so it closes #360 as well.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The intermediate JEP 524 linking stub, metadata, and JDK 26 loader registration are missing.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds the JDK 27 third-preview PEM API demo and redirects the JEP 470 preview to it.

Changes:

  • Demonstrates PEM encoding, encryption, decryption, and type inspection.
  • Registers JEP 538 and updates JEP 470 as a linking demo.
  • Adds corresponding JDK metadata.
File Description
src/​main/​resources/​JDK27Info.json Adds JEP 538 metadata.
src/​main/​resources/​JDK25Info.json Marks JEP 470 as superseded.
src/​main/​java/​org/​javademos/​java27/​jep538/​PemEncodingsDemo.java Implements the PEM API demo.
src/​main/​java/​org/​javademos/​java25/​jep470/​PemEncodingsDemo.java Converts JEP 470 into a linking stub.
src/​main/​java/​org/​javademos/​init/​Java27DemoLoader.java Registers JEP 538.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/main/java/org/javademos/java27/jep538/PemEncodingsDemo.java
@AloisSeckar
AloisSeckar merged commit d6af984 into AloisSeckar:master Sep 30, 2026
1 check passed
@AloisSeckar

Copy link
Copy Markdown
Owner

Thanks for the contribution @Akhil-1527

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JEP 538 – PEM Encodings of Cryptographic Objects (Third Preview) JEP 524 – PEM Encodings of Cryptographic Objects (Second Preview)

3 participants