【问题标题】:java.io.IOException: toDerInputStream rejects tag type 77java.io.IOException: toDerInputStream 拒绝标签类型 77
【发布时间】:2021-04-17 15:53:55
【问题描述】:

我正在尝试使用 Java 从 weblogic 服务器读取 pfx 证书,但我收到 java.io.IOException: toDerInputStream rejects tag type 77

【问题讨论】:

标签: java certificate weblogic ioexception jdeveloper


【解决方案1】:

这是给我的。
当我以字符串形式下载为 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)

【讨论】:

    【解决方案2】:

    看起来您可能正在尝试使用 .cer 证书,但它应该是 .pfx 或其他不同于 .cer 的格式。 检查您正在使用的 KeyStore 或您的证书格式。

    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();
    } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-03
      • 1970-01-01
      • 2015-02-18
      • 2012-10-07
      • 2011-07-14
      • 2018-03-11
      相关资源
      最近更新 更多