在Java中,我们要从作为私钥的字节字符串创建JKS文件。 目前,我正在使用以下代码生成默认的JKS。 如何传递字节字符串以从给定的字节生成JKS文件?
KeyStore keyStore = KeyStore.getInstance("JKS");
char[] password = "password".toCharArray();
keyStore.load(null, password);
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(1024);
KeyPair pair = kpg.generateKeyPair();
java.security.cert.Certificate[] outChain = {createCertificate("CN=CA", pair.getPublic(), pair.getPrivate()),
createCertificate("CN=Client", pair.getPublic(), pair.getPrivate())};
keyStore.setKeyEntry(String.valueOf(18), pair.getPrivate(), password, outChain);
FileOutputStream writeStream = new FileOutputStream("D:/bnb/Configuration/keys/" + "sample" + ".jks");
keyStore.store(writeStream, password);
writeStream.close();