Untitled
unknown
plain_text
2 years ago
1.2 kB
8
Indexable
import java.security.*;
import java.security.spec.ECGenParameterSpec;
public class GenerateECCKeyPair {
public static void main(String[] args) throws Exception {
// Generate ECC key pair
KeyPair keyPair = generateECCKeyPair();
// Get the public and private keys
PublicKey publicKey = keyPair.getPublic();
PrivateKey privateKey = keyPair.getPrivate();
// Print the keys
System.out.println("Public Key: " + bytesToHexString(publicKey.getEncoded()));
System.out.println("Private Key: " + bytesToHexString(privateKey.getEncoded()));
}
public static String bytesToHexString(byte[] bytes) {
StringBuilder hexString = new StringBuilder();
for (byte b : bytes) {
hexString.append(String.format("%02X", b));
}
return hexString.toString();
}
// Generate ECC key pair
public static KeyPair generateECCKeyPair() throws Exception {
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("EC");
ECGenParameterSpec ecSpec = new ECGenParameterSpec("secp256r1"); // You can choose a different curve
keyGen.initialize(ecSpec, new SecureRandom());
return keyGen.generateKeyPair();
}
}
Editor is loading...
Leave a Comment