Last active
November 13, 2018 02:39
-
-
Save kabronkline/599227ecb3acc352c94ee0d9fff7c8aa to your computer and use it in GitHub Desktop.
Generate EC Keypair in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.kabronkline.pkeydb; | |
| import java.security.*; | |
| import java.security.spec.ECGenParameterSpec; | |
| import java.util.Base64; | |
| public class ECKeyPairGenerator { | |
| public static void main(String[] args) throws InvalidAlgorithmParameterException, NoSuchProviderException, NoSuchAlgorithmException { | |
| KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("EC","SunEC"); | |
| // 256 bit key with Koblitz curve | |
| ECGenParameterSpec keyGenParamSpec = new ECGenParameterSpec("secp256k1"); | |
| keyPairGen.initialize(keyGenParamSpec); | |
| KeyPair keyPair = keyPairGen.genKeyPair(); | |
| PrivateKey privateKey = keyPair.getPrivate(); | |
| PublicKey publicKey = keyPair.getPublic(); | |
| System.out.println("Private Key: " + Base64.getEncoder().encodeToString(privateKey.getEncoded())); | |
| System.out.println("Public Key: " + publicKey.toString()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment