Java – how to compress or encode elliptic curve public keys and put them on the network?

I am developing distributed digital signatures, signing documents and sending them to application server over the network I use socket programming in Java to complete it I think we should encode or compress the public key, that is, the X and Y values are represented as single binary data in some way and stored in the public registry or network But I don't know how to do this in Java

// I have class like this 
           public class CryptoSystem{                  

               EllipticCurve ec = new EllipticCurve(new P192());

               //-------------------
               //--------------------

               public ECKeyPair generatekeyPair()
               {
                  return ECKeyPair(ec);

               }


            }    
        // i don't think i have problem in the above


    CryptoSystem crypto = new CryptoSystem();
    ECKeyPair keyPair = crypto.generateKeyPair();
    BigInteger prvKey = keyPair.getPrivateKey();
    ECPoint pubKey = keyPair.getPublicKey();
     // recommend me here to  compress and send it  the public key to a shared network.

I want to know how to encode the public key and domain parameters so that the verifier of the signature will decode it to use it Because when you send them to the verifier over the network, you will have to encode them into a single byte array. I don't use bouncy castle provider The whole implementation of ECDSA algorithm is my project

Solution

Elliptic curve points almost always use x9 62

You can choose to use point compression Coding with point compression is trivial, but decoding compression points requires more work, so I won't bother unless you really need to save additional bytes If you need, please let me know and I'll add details You can identify x9 with dot compression by the first byte (i.e. 0x02 or 0x03) 62 coding point

Coding without point compression is very simple: starting from 0x04 (indicating no compression) Then follow the X coordinate first, then the Y coordinate, and zero padding on the left until the byte size of the field:

int qLength = (q.bitLength()+7)/8;
byte[] xArr = toUnsignedByteArray(x);
byte[] yArr = toUnsignedByteArray(y);
byte[] res = new byte[1+2*qLength];
res[0] = 0x04;
System.arraycopy(xArr,res,qLength - xArr.length,xArr.length);
System.arraycopy(yArr,2* qLength - yArr.length,nLength);

Decoding this is of course trivial

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>