11/*
2- * Copyright (c) 2012, 2024 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2012, 2026 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2525// program to generate rsakeys.ks. does not need to run during testing
2626// checked into the workspace so that the keystore file can be recreated
2727// in the future if needed.
28+ //
29+ // To run:
30+ // java --add-exports java.base/sun.security.x509=ALL-UNNAMED GenKeyStore.java
2831
2932// @author Andreas Sterbenz
3033
@@ -43,26 +46,22 @@ public class GenKeyStore {
4346
4447 static final char [] password = "test12" .toCharArray ();
4548
46- private static X509Certificate getCertificate (String suffix , PublicKey publicKey , PrivateKey privateKey ) throws Exception {
49+ private static X509Certificate getCertificate (String suffix ,
50+ PublicKey publicKey ,
51+ PrivateKey privateKey ) throws Exception {
4752 X500Name name = new X500Name ("CN=Dummy Certificate " + suffix );
4853 String algorithm = "SHA1with" + publicKey .getAlgorithm ();
4954 Date date = new Date ();
50- AlgorithmId algID = AlgorithmId .getAlgorithmId (algorithm );
5155
5256 X509CertInfo certInfo = new X509CertInfo ();
53-
54- certInfo .set (X509CertInfo .VERSION , new CertificateVersion (CertificateVersion .V1 ));
55- certInfo .set (X509CertInfo .SERIAL_NUMBER , new CertificateSerialNumber (1 ));
56- certInfo .set (X509CertInfo .ALGORITHM_ID , new CertificateAlgorithmId (algID ));
57- certInfo .set (X509CertInfo .SUBJECT , name );
58- certInfo .set (X509CertInfo .ISSUER , name );
59- certInfo .set (X509CertInfo .KEY , new CertificateX509Key (publicKey ));
60- certInfo .set (X509CertInfo .VALIDITY , new CertificateValidity (date , date ));
61-
62- X509CertImpl cert = new X509CertImpl (certInfo );
63- cert .sign (privateKey , algorithm );
64-
65- return cert ;
57+ certInfo .setVersion (new CertificateVersion (CertificateVersion .V1 ));
58+ certInfo .setSerialNumber (new CertificateSerialNumber (1 ));
59+ certInfo .setSubject (name );
60+ certInfo .setIssuer (name );
61+ certInfo .setKey (new CertificateX509Key (publicKey ));
62+ certInfo .setValidity (new CertificateValidity (date , date ));
63+
64+ return X509CertImpl .newSigned (certInfo , privateKey , algorithm );
6665 }
6766
6867 private static void addToKeyStore (KeyStore ks , KeyPair kp , String name ) throws Exception {
0 commit comments