如何解决java.io.IOException: toDerInputStream 拒绝标签类型 77
我正在尝试使用 Java 从 weblogic 服务器读取 pfx 证书,但出现 java.io.IOException:toDerInputStream 拒绝标签类型 77
解决方法
看起来您可能正在尝试使用 .cer 证书,而它应该是 .pfx 或其他不同于 .cer 的格式。 检查您使用的密钥库或您的证书格式。
String strFile = "certificate.cer"; // << ((( should be .pfx )))
File file = new File(strFile);
byte[] certificateBytes = FileUtils.readFileToByteArray(file);
String password = "MyPassword123";
KeyStore keyStore = KeyStore.getInstance("PKCS12"); // << KeyStore used for .pfx
try (ByteArrayInputStream bs = new ByteArrayInputStream(certificateBytes)) {
keyStore.load(bs,password.toCharArray());
} catch (NoSuchAlgorithmException | CertificateException e) {
e.printStackTrace();
}
,
这是给我的。
当我以字符串形式下载为 base64 时。
我的代码需要它在 byte[],
我的代码告诉我“java.io.IOException:toDerInputStream 拒绝标签类型 77”。
然后我在 powershell 中执行此操作,它有效。
$fileContentBytes = get-content "the file you read from web"
$a= [System.Convert]::FromBase64String($fileContentBytes)
[IO.File]::WriteAllBytes(‘xxx.pfx’,$a)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。