资料来源: 如何从 byte[] 数组中恢复 RSA 公钥?
这是我的密钥对生成方法:
try {
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("ECDSA", "BC");
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
ECGenParameterSpec ecSpec = new ECGenParameterSpec("prime192v1");
// Initialize the key generator and generate a KeyPair
keyGen.initialize(ecSpec, random); // 256 bytes provides an
// acceptable security level
KeyPair keyPair = keyGen.generateKeyPair();
// Set the public and private keys from the keyPair
privateKey = keyPair.getPrivate();
publicKey = keyPair.getPublic();
System.out.println("Private and public keys:");
System.out.println("PRIVATE: " + StringUtil.getStringFromKey(this.privateKey));
System.out.println("PUBLIC: " + StringUtil.getStringFromKey(this.publicKey));
} catch (Exception e) {
throw new RuntimeException(e);
}