How Do i compress or encode the Elliptic curve public key and put it over the network?

前端 未结 2 2060
栀梦
栀梦 2021-02-15 12:55

I am developing Distributed digital signature that signs a document and send it through network to the Application Server.I am using socket programming in java to do it. I think

2条回答
  •  长情又很酷
    2021-02-15 13:34

    Elliptic curve points are almost always encoded using the encoding specified in X9.62.

    It is optional to use point compression. It is trivial to encode using point compression, but decoding a compressed point needs a bit more work, so unless you really need to save the extra bytes, I would not bother. Let me know if you need it, and I will add the details. You can recognize X9.62 encoded points with point compression by the first byte, which will be 0x02 or 0x03.

    Encoding without point compression is really simple: start with a 0x04 (to indicate no compression). Then follow with first the x coordinate, then the y coordinate, both zero-padded on the left up to the size in bytes 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, 0, res, qLength - xArr.length, xArr.length);
    System.arraycopy(yArr, 0, res, 2* qLength - yArr.length, nLength);
    

    Decoding this is of course trivial.

提交回复
热议问题