der 格式抛出 CRYPTO_internal header too long 错误

发布时间:2021-03-01 21:27

我正在尝试编写代码片段以下载 der 格式的文件。

代码片段:

public ResponseEntity<ByteArrayResource> downloadCertificate(final HttpServletResponse response){
certificateInputStream = fetchCertDataInDERFormat();

//create a file with contents
//        try {
//            File file = new File("<>/Downloads/byteCert.der");
//            OutputStream os = new FileOutputStream(file);
//            os.write(certInputStream.readAllBytes());
//            os.close();
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }

HttpHeaders header = new HttpHeaders();
        header.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; headerCert.der");
        header.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE);
        ByteArrayResource resource = new ByteArrayResource(certificateInputStream.readAllBytes());
        return ResponseEntity.ok()
                .headers(header)
                .body(resource);
}

尝试通过 openssl 命令检查响应正文时抛出以下错误:

<块引用> <块引用>

openssl x509 -inform der -in certPostman.der -noout -subject -issuer 无法加载证书 4475899500:错误:0DFFF07B:asn1 编码例程:CRYPTO_internal:头文件太长:/AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-47.140.1/libressl-2.81/crypton1 .c:152:

我已经确定的事情:

  1. 正文的内容很好,因为我能够使用 openssl 成功检查 byteCert.der(代码注释)的内容。
  2. 在其他 Stackoverflow 论坛中建议的任何 spring 标题,如内容处置、字符编码或内容类型更改都没有帮助。

任何人都可以提出任何好的意见。

回答1