2011-03-11 5 views
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}); 
     } 

キーが生成されますが、それは、秘密鍵を格納する証明書チェーンを要求します。 それは今問題です。どのように私は認証チェーンを生成することができます、私は認定を最初に生成する必要がありますはい、どのように?

+0

あなたの質問はあまりにも曖昧です。あなたは何をしようとしていますか?どのような環境(JEE、デスクトップなど)ですか?あなたは今まで何をしましたか? –

答えて

0

何を達成しようとしているのかわかりませんが、少し前にこの小さなアプリ(ソースコードを含む)を使用して、既存の秘密鍵をキーストアに挿入しました。 http://www.agentbob.info/agentbob/79-AB.html

+0

ありがとうございます、しかし、それは私がallready作成されたファイルとして証明書を持っているときに動作します。私はそれを何とか生成する必要があると思う.. – hs2d

+0

自己署名証明書を生成しようとしている場合は、apacheを使用します。下のリンクを参照してください。 http://slacksite.com/apache/certificate.php – isurusndr

0

私は投稿http://www.pixelstech.net/article/1406726666-Generate-certificate-in-Java----2が純粋なJavaで証明書チェーンを生成する方法を示すと信じています。 Bouncy Castleを使う必要はありません。

このポストは、長さが1より長い証明書チェーンを生成する方法を示します。インターネット上のほとんどのポストでは、長さ1の証明書チェーンの作成、またはBCの使用が示されます。

関連する問題