如何压缩或编码椭圆曲线公钥并将其放在网络上? [英] How Do i compress or encode the Elliptic curve public key and put it over the network?

查看:300
本文介绍了如何压缩或编码椭圆曲线公钥并将其放在网络上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发分布式数字签名签署一个文档,并通过网络发送到应用程序服务器。我使用套接字编程在java中做到这一点。我认为公共密钥应该编码或压缩,即x和y值以某种方式表示为一个单一的二进制数据,并保存在公共注册表或网络。但我不知道如何在Java中做。

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 the public key should be encoded or compressed i.e the x and y values are somehow represented as a single binary data and saved in a public registry or network.But i don't know how to do it 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.

我想知道如何对公钥和域参数进行编码,以便签名的验证者将解码它使用它。因为当你通过网络发送他们到验证器,我们必须编码为单个字节数组。我没有使用Bouncy城​​堡提供程序。椭圆曲线点几乎总是使用X9.62中指定的编码进行编码。ECDSA算法的整个实现是我的项目。

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 over the network to the verifier u gonna have to encode the as a single byte array.i am no using Bouncy Castle Provider. The whole implementation of ECDSA algorithm is my project

推荐答案

使用点压缩是可选的。使用点压缩编码是微不足道的,但解码压缩点需要更多的工作,所以除非你真的需要保存额外的字节,我不会打扰。让我知道,如果你需要它,我会添加的细节。你可以识别X9.62编码点的点压缩的第一个字节,这将是0x02或0x03。

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.

无点压缩的编码真的很简单:开始一个0x04 (以指示没有压缩)。然后首先跟随x坐标,然后是y坐标,都在左边填充到字段的字节大小:

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);

解码这当然很简单。

这篇关于如何压缩或编码椭圆曲线公钥并将其放在网络上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆