简体   繁体   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] This is the code for elliptic curve cryptography for public and private key generation but when I executed this code ,showing only the public key but not the private key,so please help me out and let me know ,what to do to generate the private key!! [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);
        }
    }
}

I've just tested the above code. 我刚刚测试了上面的代码。

Output 输出量

Sun EC private key, 192 bits private value: 3248833611418544793834748156439256292267803494576663573112 Sun EC私钥,192位私有值:324883361141854474473473471156156256292267803494576663573112
parameters: secp192r1 [NIST P-192, X9.62 prime192v1] (1.2.840.10045.3.1.1) Sun EC public key, 192 bits public x coord: 5122655651118956061783347731888893733494103991283417332818 public y coord: 223043343028867724454216740788693823451155477884918709166 参数:secp192r1 [NIST P-192,X9.62 prime192v1](1.2.840.10045.3.1.1) Sun EC公钥,192位 public x坐标:5122655651118956061783341881883733494104103991283417332818 public y坐标:223043343028867724454216740788693823451
parameters: secp192r1 [NIST P-192, X9.62 prime192v1] (1.2.840.10045.3.1.1) 参数:secp192r1 [NIST P-192,X9.62 prime192v1](1.2.840.10045.3.1.1)

Are you getting the same output? 您得到相同的输出吗?

暂无
暂无

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

相关问题 当我尝试在下面的代码中打印为RSA生成的公钥和私钥时,我得到了什么? - What I am getting when i am trying to print Public and private key generated for RSA in code below? 我应该使用哪些加密算法来使用私钥加密数据并使用公钥解密数据? - What cryptographic algorithms should I use to encrypt data using private key and decrypt data using public key? 如何使用Java的RSA私钥和公钥加密并发送DES密钥? - How do I encrypt and send DES key with RSA private key and then public key in Java? 我需要在java中读取已经给出的公钥和私钥。 我无法请教 - I need to read a public and private key in java which is already given. I am not able to please advise 如何使用匹配的DER私钥解密公共PEM密钥加密的字节数组? - How do I decrypt a public PEM key encrypted byte array using a matching DER private key? 将私钥从PuTTY转换为OpenSSH格式后,是否需要向服务器添加新的公钥? - Do I need to add new public key to the server after converting private key from PuTTY to OpenSSH format? 如何使用Bouncy Castle从Java中的ECDSA私钥中获取公钥? - How do I obtain the public key from an ECDSA private key in Java with Bouncy Castle? 我想使用 Android KeyChain 来存储公钥和私钥 - I want to use Android KeyChain to store public key and private key 我在解密使用 RSA 生成的公钥(.jks)编码的 128 位 AES 密钥时收到 BadPaddingException - I am getting BadPaddingException while decrypting an 128 bit AES key which has been encoded by using RSA generated public key(.jks) 我应该如何创建Hashtable <Key, Value> 什么时候我不在乎什么存储在Value中? - How should I create Hashtable<Key, Value> when I do not care what is stored in Value?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM