我得到了一个Java应用程序,它在1.62版本上使用BouncyCastle bcprov-jdk15。我将显示以下源代码:
Pom文件:
<dependencies>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.62</version>
<scope>provided</scope>
</dependency>
</dependencies>
CSR.java
import org.bouncycastle.asn1.DEROutputStream;
...
public String createSigningRequest(String signAlgorithm, String subject, PublicKey publicKey, PrivateKey privateKey, String provName) {
StringBuilder sb = null;
try {
sb = new StringBuilder();
X509Name xname = new X509Name(subject);
PKCS10CertificationRequest csr = new PKCS10CertificationRequest(signAlgorithm, xname, publicKey , null, privateKey, provName);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DEROutputStream deros = new DEROutputStream(baos);
deros.writeObject(csr.toASN1Primitive());
String sTmp = new String(org.bouncycastle.util.encoders.Base64.encode(baos.toByteArray()));
sb.append(HEADER_CSR_PEM);
for (int iCnt=0; iCnt < sTmp.length(); iCnt+=CERT_REQ_LINE_LENGTH) {
int iLineLength;
if ((iCnt + CERT_REQ_LINE_LENGTH) > sTmp.length()) {
iLineLength=sTmp.length() - iCnt;
}
else {
iLineLength=CERT_REQ_LINE_LENGTH;
}
sb.append(sTmp.substring(iCnt,iCnt + iLineLength)).append("n");
}
sb.append(FOOTER_CSR_PEM);
return sb.toString();
} catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidKeyException | SignatureException | IOException ex) {
errorMessage = ex.getLocalizedMessage();
LOG.error("createSigningRequest : " + ex.getLocalizedMessage());
}
return "";
}
另一方面,还有Maven存储库中的BouncyCastle bcprov-jdk15on 1.69。所以我用这个新版本升级了pom文件。尽管如此,我还是有以下拼写错误的说明:
import org.bouncycastle.asn1.DEROutputStream; //DEROutputStream is not public in org.bouncycastle.asn1; cannot be accessed from outside package
...
DEROutputStream deros = new DEROutputStream(baos); //DEROutputStream is not public in org.bouncycastle.asn1; cannot be accessed from outside package
...
} catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidKeyException | SignatureException | IOException ex) { //exception IOException is never thrown in body of corresponding try statement
这三条指令不被认可。我的问题是,根据1.69上的bcprov-jdk15,要更改的新指令是什么?
- 添加:";当我用jdk 1.8u341部署到Wildfly 10时出错
我得到以下错误:
Cannot upload deployment:
{"WFLYCTL0080: Failed services" =>
{"jboss.undertow.deployment.default-server.default-host./myJavaApp" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./myJavaApp: java.lang.ArrayIndexOutOfBoundsException: 51201
Caused by: java.lang.ArrayIndexOutOfBoundsException: 51201"},
"WFLYCTL0412: Required services that are not installed:" => ["jboss.undertow.deployment.default-server.default-host./myJavaApp"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => undefined}
如果您查看DEROutputStream
的文档,那么您可以阅读构造函数的以下文本(我已经提到1.66,但它也已经在1.64中了,可能以前也有(:
已弃用将
ASN1OutputStream.create(OutputStream, String)
与ASN1Encoding.DER
一起使用。
是的,对Bouncy的轻量级API的更改有点令人烦恼,整个类可能已经被弃用了。