0
嗨,我希望你們都是okey 我使用的是opensaml-j v3,我很努力地用後者創建一個憑證,但我不知道如何創建它。如何使用opensaml-j創建證書?
這裏是我的源代碼
`private static Credential getCredential() throws IOException,
NoSuchAlgorithmException, InvalidKeySpecException, CertificateException{
InputStream is=new FileInputStream("C:\\openssl keys\\key.pk8");
CertificateFactory cf=CertificateFactory.getInstance("X.509");
X509Certificate cer=(X509Certificate) cf.generateCertificate(is);
BasicX509Credential basicCredential=new BasicX509Credential(cer);
basicCredential.setUsageType(UsageType.SIGNING);
return basicCredential;
}`
這裏的堆棧跟蹤
Exception in thread "main" java.security.cert.CertificateParsingException: signed fields invalid
\t at sun.security.x509.X509CertImpl.parse(Unknown Source)
\t at sun.security.x509.X509CertImpl.<init>(Unknown Source)
\t at sun.security.provider.X509Factory.engineGenerateCertificate(Unknown Source)
\t at java.security.cert.CertificateFactory.generateCertificate(Unknown Source)
\t at memory.CreateSamlAssertion.getCredential(CreateSamlAssertion.java:108)
\t at memory.CreateSamlAssertion.createAssertion(CreateSamlAssertion.java:61)
\t at memory.SamlTest.main(SamlTest.java:42)
的錯誤是在這一行:
X509Certificate cer=(X509Certificate) cf.generateCertificate(is);
所以我只是有一個簡單的問題:
有人可以告訴我一個源代碼如何創建一個憑證?