This discussion is archived
6 Replies Latest reply: Jan 11, 2012 1:05 PM by EJP RSS

ECC key generation

909533 Newbie
Currently Being Moderated
Hi
Am new to java.i have generated public and private key using Elliptic curve cryptography.Now i need to retrieve Generator G value.please suggest me some ideas how to retrieve it.Here's my code...
package ecc.keygeneration.pkgnew;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Security;
import de.flexiprovider.core.FlexiCoreProvider;
import de.flexiprovider.ec.FlexiECProvider;
import de.flexiprovider.ec.parameters.CurveParams;
import de.flexiprovider.ec.parameters.CurveRegistry.BrainpoolP160r1;
import org.bouncycastle.math.ec.ECCurve;
import org.bouncycastle.math.ec.ECPoint;
import java.math.BigInteger;
import java.security.spec.AlgorithmParameterSpec;
import org.bouncycastle.jce.spec.ECParameterSpec;

public class EccKeygenerationNew {
public static void main(String[] args) throws Exception {
Security.addProvider(new FlexiCoreProvider());
Security.addProvider(new FlexiECProvider());

KeyPairGenerator kpg = KeyPairGenerator.getInstance("ECIES", "FlexiEC");

CurveParams ecParams = new BrainpoolP160r1();

kpg.initialize(ecParams, new SecureRandom());
KeyPair keyPair = kpg.generateKeyPair();
PublicKey pubKey = keyPair.getPublic();
System.out.println(pubKey);
PrivateKey privKey = keyPair.getPrivate();
System.out.println(privKey);

}
}
  • 1. Re: ECC key generation
    sabre150 Expert
    Currently Being Moderated
           KeyPair keyPair = kpg.generateKeyPair();
            ECPublicKey pubKey = (ECPublicKey) keyPair.getPublic();
            System.out.println(pubKey);
            ECPrivateKey privKey = (ECPrivateKey) keyPair.getPrivate();
            System.out.println(privKey);
            System.out.println(privKey.getParams().getG());
  • 2. Re: ECC key generation
    909533 Newbie
    Currently Being Moderated
    hi
    Thanks a lot for your code..but i was not able to get privatekey.getparams...itz showing some error..i hope some header files are missing.please suggest me appropriate header file for private key or else is there any other jar files i should include..
  • 3. Re: ECC key generation
    EJP Guru
    Currently Being Moderated
    itz showing some error
    Well that's informative.
    please suggest me appropriate header file for private key or else is there any other jar files i should include
    It is impossible for anyone else to solve 'some error' until you confide in us what the actual error message is, but there are no header files in Java so that eliminates one possibility.
  • 4. Re: ECC key generation
    909533 Newbie
    Currently Being Moderated
    In line 33 it shows cannot find symbol.Symbol: method getparams() ,location:variable Privkey of type java.security.Privatekey.something i missed out.please suggest me how to fix this error.
  • 5. Re: ECC key generation
    sabre150 Expert
    Currently Being Moderated
    906530 wrote:
    In line 33 it shows cannot find symbol.Symbol: method getparams() ,location:variable Privkey of type java.security.Privatekey.something i missed out.please suggest me how to fix this error.
    I showed you exactly how to fix the soddin error. Since in your situation the PrivateKey is an ECPrivateKey, you cast the PrivateKey to an ECPrivateKey. I did test this so I know I have it exactly right. Of course I assumed that you were minimally Java literate and would know a) that Java is case sensitive (it's getParams() and not getparams()) , b) what a cast is and c) that you would need to add the relevant flexiprovider imports (the flexiprovider Javadoc will provide this information).
  • 6. Re: ECC key generation
    EJP Guru
    Currently Being Moderated
    You could also try copy/pasting correctly when someone goes to the trouble of posting actual code.you seem to be just wasting time in every possible way.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points