0

我需要在我的 java 应用程序中生成证书链,因为在将私钥存储到密钥库时需要它?谁能帮帮我。我不知道该怎么做。。

我需要生成 RSA 密钥对,然后将其存储到密钥库。现在我的代码如下所示:

public static void main(String[] args)
{
            String issuerDN = null;
            String addKeyName = "mynewkey";
    String delKeyName = null;
    String password = "2222";
    boolean listStore = true;
            boolean deleteKeysAftherWrap = false;

    try
    {
        /* make sure that we have access to the eracom provider */
        Provider p = new ERACOMProvider();
        Security.addProvider(p);

                    int keySize = 1024;
        KeyPair keyPair = null;

        /* get the eracom keystore - access to the adapter */
        KeyStore keyStore = KeyStore.getInstance("CRYPTOKI", p.getName());

        /* LOAD the keystore from the adapter */
        keyStore.load(null, password.toCharArray());

        if (addKeyName != null)
        {
            /* This key cannot be added to the keystore if it already exists */
            if (keyStore.containsAlias(addKeyName))
            {
                println("");
                println("Key name already exists");
                println("");
            }

            KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA", p.getName());

                            keyPairGenerator.initialize(keySize);

                            keyPair = keyPairGenerator.generateKeyPair();

                            PublicKey pubKey = keyPair.getPublic();
                            PrivateKey privKey = keyPair.getPrivate();

            keyStore.setKeyEntry("newpub", pubKey, null, null);
                            keyStore.setKeyEntry("newpriv", privKey, null, null});
        }

生成了密钥,但它要求证书链存储私钥。这就是现在的问题。我如何生成认证链,我是否必须先生成认证,如果是,那么如何?

4

2 回答 2

0

不确定您要实现什么,但前段时间我使用这个小应用程序(包括源代码)将现有私钥插入密钥库。希望你会发现这很有用:http ://www.agentbob.info/agentbob/79-AB.html

于 2011-03-11T10:15:51.273 回答
0

我相信这篇文章http://www.pixelstech.net/article/1406726666-Generate-certificate-in-Java----2将向您展示如何使用纯 Java 生成证书链。它不需要您使用 Bouncy Castle。

这篇文章将向您展示如何生成长度大于 1 的证书链。而 Internet 上的大多数帖子将向您展示如何创建长度为 1 的证书链或使用 BC。

于 2014-10-15T09:33:30.780 回答