6 Replies Latest reply: May 17, 2012 10:33 AM by sabre150 RSS

    conversion of public key to biginteger

    909533
      Can anyone please help me to fix up this issue? I need to convert the public key to a BigInteger. Here the public key is ECPoint which is a point on the curve (x,y). I don't know how to convert this into a BigInteger.heres my code..
      public static void main(String[] args) throws Exception {
      Security.addProvider(new BouncyCastleProvider());
      ECCurve curve = new ECCurve.Fp(
      new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q
      new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
      new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b

      ECParameterSpec ecSpec = new ECParameterSpec(
      curve,
      curve.decodePoint(Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
      new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307")); // n
      KeyPairGenerator kpg = KeyPairGenerator.getInstance("ECDSA", "BC");
      kpg.initialize(ecSpec, new SecureRandom());
      KeyPair keyPair = kpg.generateKeyPair();
      PublicKey pubKey = keyPair.getPublic();
      System.out.println(pubKey);
      PrivateKey privKey = keyPair.getPrivate();
      System.out.println(privKey);
      BigInteger s = ((ECPrivateKey) privKey).getS();
      System.out.println(s);
      java.security.spec.ECPoint a = ((ECPublicKey) pubKey).getW();
        • 1. Re: conversion of public key to biginteger
          sabre150
          You can't represent the java.security.spec.ECPoint as a single BigInteger (or at least not without some reversible transformation of the two component parts). Check the Javadoc for java.security.spec.ECPoint .
          • 2. Re: conversion of public key to biginteger
            EJP
            Here the public key is ECPoint which is a point on the curve (x,y). I don't know how to convert this into a BigInteger.
            You can't convert it to a single number, because it is two numbers. Surely this is obvious?
            • 3. Re: conversion of public key to biginteger
              909533
              hi thanks for your response..please do suggest me any other methods to convert the public key into biginteger..for converting the private key into biginteger i used these code..
              BigInteger s = ((ECPrivateKey) privKey).getS();
              is there any methods like this for public key also??while am surfing about this i got this..we can get the value of X and Y by using getAffineX() and getAfiineY() and finally by using XOR operation (x,y)values can be converted into single value..but i dont know how to use this methods...
              • 4. Re: conversion of public key to biginteger
                EJP
                hi thanks for your response
                Have you read it?
                please do suggest me any other methods to convert the public key into biginteger
                Err, no, you haven't read it. The public key is composed of two numbers. (x,y) You can convert each of those to a BigInteger. You can't convert the key itself to a BigInteger, because it isn't a number. It is two numbers. I already said that.
                for converting the private key into biginteger i used these code..
                BigInteger s = ((ECPrivateKey) privKey).getS();
                That code converts one of the numbers comprising the private key to a BigInteger. It isn't useful without the other nunber, and it doesn't constitute 'convert[ing] the private key to a BigInteger'.

                I seem to be repeating myself here. Why is that?
                by using XOR operation (x,y)values can be converted into single value
                Certainly, but the process loses information so you cannot recover the key from that number.
                > but I don't know how to use this methods ...
                You don't know how to use XOR?
                • 5. Re: conversion of public key to biginteger
                  909533
                  thanks for your response...anyway i tried and i got it by using getaffine methods..
                  • 6. Re: conversion of public key to biginteger
                    sabre150
                    906530 wrote:
                    thanks for your response...anyway i tried and i got it by using getaffine methods..
                    You didn't get the PublicKey as a BigInteger by "using getaffine methods" ! You got TWO BigInteger values which, as we explained 3 times, are the component parts of the key!