我正在使用帶bcprov-jdk15on-147 jar的BouncyCastle API生成CSR。無法編寫使用org.bouncycastle.asn1.pkcs.CertificationRequest以PEM文件格式生成的CSR
CertificationRequestInfo certInfo = new CertificationRequestInfo(subject, subKeyInfo, new DERSet(attribute));
org.bouncycastle.operator.ContentSigner sigGen = null;
sigGen = new JcaContentSignerBuilder("SHA1withRSA").setProvider("BC").build(privateKey);
org.bouncycastle.asn1.pkcs.CertificationRequest ctest = new org.bouncycastle.asn1.pkcs.CertificationRequest(certInfo,sigAlgName,new DERBitString(sigGen.getSignature()));
我傳遞這obejct到我的調用函數:
GenerateCSR gcsr = GenerateCSR.getInstance();
System.out.println("Public Key:\n"+gcsr.getPublicKey().toString());
System.out.println("Private Key:\n"+gcsr.getPrivateKey().toString());
org.bouncycastle.asn1.pkcs.CertificationRequest csr = gcsr.getCSR("IMO");
System.out.println("CSR Request Generated!!");
FileWriter fcsr = new FileWriter("C:\\test.txt");
PEMWriter w1 = new PEMWriter(fcsr);
w1.writeObject(csr);
但我得到以下異常:
Exception in thread "main" org.bouncycastle.util.io.pem.PemGenerationException: unknown object passed - can't encode.
at org.bouncycastle.openssl.MiscPEMGenerator.createPemObject(Unknown Source)"