相关疑难解决方法(0)

使用给定私钥在椭圆曲线算法中生成公钥的代码

我需要使用jdk 1.7实现ECC(椭圆曲线加密)算法.我尝试使用充气城堡,sunEC,但他们都给出了错误和错误.我的目标是使用私钥生成椭圆曲线,我将被赋予系统.

因此,我需要使用jdk1.7获取使用给定私钥生成公钥的准确代码.我使用的IDE是ecllipse.我需要知道,除了私钥之外,我应该给出的其他参数是什么?提供一个曲线点和私钥是否足够?

有人可以帮助我从私钥生成公钥吗?我可以管理其余的实现.

任何知道使用java实现Elliptic Curve Cryptography键的人,请告诉我这段代码是否正确?

public class ECCrypt {

    private ECPoint curve_point;

      public ECCrypt(ECPoint curve_point) {
        this.curve_point = curve_point;
      }

public BigInteger makePublicKey(BigInteger privateKey) {
        ECPoint ecPublicKey = new ECPoint(curve_point);
        ecPublicKey.mult(privateKey);
        return ecPublicKey.pack();
}


public static void main(String[] argv) throws Exception {
        java.util.Random rnd = new java.util.Random();
        ECPoint cp = new ECPoint();
        cp.random(rnd);
        ECCrypt ec = new ECCrypt(cp);
        BigInteger priv = new BigInteger(255,rnd);
        BigInteger pub = ec.makePublicKey(priv);

}
Run Code Online (Sandbox Code Playgroud)

谢谢!

java bouncycastle elliptic-curve

5
推荐指数
1
解决办法
1万
查看次数

在 Java 中使用 BouncyCastle 使用 ECIES 进行加密

我正在尝试使用 Java 中的 BouncyCastle 使用 ECC 算法加密一些内容。但是我得到了 BouncyCastle 库的例外,说不能投射JCEECPublicKeyIESKey. 据我所知,生成的公钥KeyPairGeneratorJCEECPublicKey不能在javaCipher.init方法中使用的。有人可以告诉我如何将其转换为公钥或 X509 规范,以便我可以在加密中使用它。

这是我试过的代码

// add instance of provider class
Security.addProvider(new BouncyCastleProvider());

// initializing parameter specs secp256r1/prime192v1
ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("prime192v1");

// key pair generator to generate public and private key
KeyPairGenerator generator = KeyPairGenerator.getInstance("ECDH", new BouncyCastleProvider());

// initialize key pair generator
generator.initialize(ecSpec);

// Key pair to store public and private key
KeyPair keyPair = generator.generateKeyPair();

Cipher iesCipher = Cipher.getInstance("ECIES", new …
Run Code Online (Sandbox Code Playgroud)

java encryption cryptography bouncycastle elliptic-curve

4
推荐指数
1
解决办法
8368
查看次数