Add java25-features module: the 18 JEPs of JDK 25 with runnable demos, captured output and compile-error cases
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b5uFE41EgmSXEP4axJ
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
876ae1bb5c
commit
1fb1455734
@@ -0,0 +1,19 @@
|
||||
import javax.crypto.KDF;
|
||||
import javax.crypto.spec.HKDFParameterSpec;
|
||||
import java.util.HexFormat;
|
||||
|
||||
/** JEP 510 (final in 25): HKDF through the new javax.crypto.KDF API, checked against RFC 5869 test case 1. */
|
||||
public class KdfDemo {
|
||||
public static void main(String[] args) throws Exception {
|
||||
HexFormat hex = HexFormat.of();
|
||||
byte[] ikm = hex.parseHex("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b");
|
||||
byte[] salt = hex.parseHex("000102030405060708090a0b0c");
|
||||
byte[] info = hex.parseHex("f0f1f2f3f4f5f6f7f8f9");
|
||||
KDF kdf = KDF.getInstance("HKDF-SHA256");
|
||||
byte[] okm = kdf.deriveData(HKDFParameterSpec.ofExtract().addIKM(ikm).addSalt(salt).thenExpand(info, 42));
|
||||
String expected = "3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865";
|
||||
System.out.println("OKM " + hex.formatHex(okm));
|
||||
System.out.println("RFC 5869 " + expected);
|
||||
System.out.println("match " + hex.formatHex(okm).equals(expected));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user