Why I can't restore ec public key?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Why I can't restore ec public key?

zhouziyan
Hi All,

Anybody can help me about EC point encode/decode question?

I generated an EC public key with 32-byte random private key, then I do
getEncode/decodePoint as following code.

I got different output result while printing out pubkey and decoded.


pubkey = ECC.secp256r1.getG().multiply(new BigInteger(1, privateKey));
System.out.println(pubkey);
byte encoded[] = pubkey.getEncoded(true);
ECPoint decoded = ECC.secp256r1.getCurve().decodePoint(encoded);
System.out.println(decoded);


outputs

=======

pubkey:

(211a0d35200f26f83d910fd087bad40757eb56ca6ac49f78ba2ad2a9e31cad5f,84b69e5dc1381881890c3fd6f30a3b240260896cccc02c16e877ed902e16d639,24304f1631ee93ad80ddbdd8a26e4c7febb47b9e3e82e47f282d79b8915ffe71,a0aaef0e752a317d40bd643dd95bf24f54696694754b1447d95905b61a92d406)

decoded:

(6ff03b949241ce1dadd43519e6960e0a85b41a69a05c328103aa2bce1594ca16,3c4f753a55bf01dc53f6c0b0c7eee78b40c6ff7d25a96e2282b989cef71c144a,1,ffffffff00000001000000000000000000000000fffffffffffffffffffffffc)


Why I can't restore the pubkey?


Many Thanks,

Ziyan


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Why I can't restore ec public key?

Peter Dettman-3
Hi Ziyan,
The EC code uses projective coordinates by default. In projective
coordinates there are multiple representations for the same point.
Try calling:
        pubKey = pubKey.normalize();

before you print out the value. This will give you the unique
representation with Z == 1, which will be the same as that returned from
decodePoint.

Regards,
Pete Dettman

On 31/05/2017 7:22 PM, zhouziyan wrote:

> Hi All,
>
> Anybody can help me about EC point encode/decode question?
>
> I generated an EC public key with 32-byte random private key, then I do
> getEncode/decodePoint as following code.
>
> I got different output result while printing out pubkey and decoded.
>
>
> pubkey = ECC.secp256r1.getG().multiply(new BigInteger(1, privateKey));
> System.out.println(pubkey);
> byte encoded[] = pubkey.getEncoded(true);
> ECPoint decoded = ECC.secp256r1.getCurve().decodePoint(encoded);
> System.out.println(decoded);
>
>
> outputs
>
> =======
>
> pubkey:
>
> (211a0d35200f26f83d910fd087bad40757eb56ca6ac49f78ba2ad2a9e31cad5f,84b69e5dc1381881890c3fd6f30a3b240260896cccc02c16e877ed902e16d639,24304f1631ee93ad80ddbdd8a26e4c7febb47b9e3e82e47f282d79b8915ffe71,a0aaef0e752a317d40bd643dd95bf24f54696694754b1447d95905b61a92d406)
>
>
> decoded:
>
> (6ff03b949241ce1dadd43519e6960e0a85b41a69a05c328103aa2bce1594ca16,3c4f753a55bf01dc53f6c0b0c7eee78b40c6ff7d25a96e2282b989cef71c144a,1,ffffffff00000001000000000000000000000000fffffffffffffffffffffffc)
>
>
>
> Why I can't restore the pubkey?
>
>
> Many Thanks,
>
> Ziyan
>
>


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Why I can't restore ec public key?

zhouziyan
Hi Pete,

On 2017/6/4 22:54, Peter Dettman wrote:
> Hi Ziyan,
> The EC code uses projective coordinates by default. In projective
> coordinates there are multiple representations for the same point.
> Try calling:
> pubKey = pubKey.normalize();
>
> before you print out the value. This will give you the unique
> representation with Z == 1, which will be the same as that returned from
> decodePoint.
Got it. THANKS!

Ziyan

>
> Regards,
> Pete Dettman
>
> On 31/05/2017 7:22 PM, zhouziyan wrote:
>> Hi All,
>>
>> Anybody can help me about EC point encode/decode question?
>>
>> I generated an EC public key with 32-byte random private key, then I do
>> getEncode/decodePoint as following code.
>>
>> I got different output result while printing out pubkey and decoded.
>>
>>
>> pubkey = ECC.secp256r1.getG().multiply(new BigInteger(1, privateKey));
>> System.out.println(pubkey);
>> byte encoded[] = pubkey.getEncoded(true);
>> ECPoint decoded = ECC.secp256r1.getCurve().decodePoint(encoded);
>> System.out.println(decoded);
>>
>>
>> outputs
>>
>> =======
>>
>> pubkey:
>>
>> (211a0d35200f26f83d910fd087bad40757eb56ca6ac49f78ba2ad2a9e31cad5f,84b69e5dc1381881890c3fd6f30a3b240260896cccc02c16e877ed902e16d639,24304f1631ee93ad80ddbdd8a26e4c7febb47b9e3e82e47f282d79b8915ffe71,a0aaef0e752a317d40bd643dd95bf24f54696694754b1447d95905b61a92d406)
>>
>>
>> decoded:
>>
>> (6ff03b949241ce1dadd43519e6960e0a85b41a69a05c328103aa2bce1594ca16,3c4f753a55bf01dc53f6c0b0c7eee78b40c6ff7d25a96e2282b989cef71c144a,1,ffffffff00000001000000000000000000000000fffffffffffffffffffffffc)
>>
>>
>>
>> Why I can't restore the pubkey?
>>
>>
>> Many Thanks,
>>
>> Ziyan
>>
>>
>


Loading...