繁体   English   中英

当我执行代码时,仅生成公钥而不生成私钥,那该怎么办?

[英]when I am executing the code only public key is generated but not the private key ,so what should I do?

package com.project;
import java.security.*;
import java.security.spec.*;

public class ECCKeyGeneration {
  public static void main(String[] args) throws Exception {
    KeyPairGenerator kpg;
    kpg = KeyPairGenerator.getInstance("EC","SunEC");
    ECGenParameterSpec ecsp;
    ecsp = new ECGenParameterSpec("secp192r1");
    kpg.initialize(ecsp);

    KeyPair kp = kpg.genKeyPair();
    PrivateKey privKey = kp.getPrivate();
    PublicKey pubKey = kp.getPublic();

    System.out.println(privKey.toString());
    System.out.println(pubKey.toString());
  }
}

[2]这是用于生成公钥和私钥的椭圆曲线密码的代码,但是当我执行此代码时,仅显示公钥而不显示私钥,因此请帮助我,让我知道,该怎么做私钥!!

import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.ECGenParameterSpec;

public class ECCKeyGeneration {

    public static void main(String[] args)  {
        try {
            KeyPairGenerator kpg;
            kpg = KeyPairGenerator.getInstance("EC","SunEC");
            ECGenParameterSpec ecsp;
            ecsp = new ECGenParameterSpec("secp192r1");
            kpg.initialize(ecsp);

            KeyPair kp = kpg.genKeyPair();
            PrivateKey privKey = kp.getPrivate();
            PublicKey pubKey = kp.getPublic();

            System.out.println(privKey.toString());
            System.out.println(pubKey.toString());
        } catch (Exception ex) {
            System.out.println(ex);
        }
    }
}

我刚刚测试了上面的代码。

输出量

Sun EC私钥,192位私有值:324883361141854474473473471156156256292267803494576663573112
参数:secp192r1 [NIST P-192,X9.62 prime192v1](1.2.840.10045.3.1.1) Sun EC公钥,192位 public x坐标:5122655651118956061783341881883733494104103991283417332818 public y坐标:223043343028867724454216740788693823451
参数:secp192r1 [NIST P-192,X9.62 prime192v1](1.2.840.10045.3.1.1)

您得到相同的输出吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM