无论如何我可以生成始终相同的私钥吗?我厌倦了使用相同的RandomSecure对象初始化KeyPairGenerator:seed
private PrivateKey getPrivateKey(String seed) {
try {
SecureRandom sr = new SecureRandom(seed.getBytes());
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(1024, sr);
KeyPair keyPair = keyGen.generateKeyPair();
return keyPair.getPrivate();
} catch (NoSuchAlgorithmException e) {
System.out.println("Failed to generate key pair!");
}
return null;
}
我调用上述函数并检查私钥是否相同:
String seed = "xyzabc123";
PrivateKey key1 = getPrivateKey(seed);
PrivateKey key2 = getPrivateKey(seed);
boolean same = key1.equals(key2); // false
它们是不同的,我的问题是有没有办法生成始终相同的私钥?