デジタル証明書を生成するコードの記述
そして、ブラウザにインストールするとエラーが発生します
ファイルのデコードに失敗しました。PKCS #12 形式ではないか、破損しているか、入力したパスワードが正しくありません。
しかし、満足するためにそのパスワードを追加する方法がわかりません PKCS #12 format
。それと一緒に行く方法は?
public KeyPair generateKeyPair() {
KeyPair pair = null;
try {
String password = "1234";
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
SecureRandom random = Utils.createFixedRandom();
keyGen.initialize(1024, random);
pair = keyGen.generateKeyPair();
PrivateKey privkey1 = pair.getPrivate();
PublicKey pubKey1 = pair.getPublic();
byte[] privateKeyBytes = pair.getPrivate().getEncoded();
byte[] encryptedPrivateKeyBytes = passwordEncrypt(
password.toCharArray(), privateKeyBytes);
//Problem might be here
Signature dsa = Signature.getInstance("SHA1withRSA");
dsa.initSign(privkey1);
Cipher cipher = Cipher
.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, pubKey1, random);
byte[] input = new byte[] { (byte) 0xbe, (byte) 0xef };
System.out.println("input : " + Utils.toHex(input));
byte[] cipherText = cipher.doFinal(input);
System.out.println("cipher: " + Utils.toHex(cipherText));
cipher.init(Cipher.DECRYPT_MODE, privkey1);
byte[] plainText = cipher.doFinal(cipherText);
System.out.println("plain : " + Utils.toHex(plainText));
} catch (Exception e) {
System.err.println("Caught exception " + e.toString());
}
return pair;
}
証明書が正常に生成され、ここで停止しました。
ヒントをありがとう。