签名长度不正确:得到3300,但预期为512

5n0oy7gb  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(420)

我正在使用bouncy castle验证由js库签名的pdf签名:

PDDocument signedDocument = PDDocument.load(file);
    List<PDSignature> signatureDictionaries = signedDocument.getSignatureDictionaries();
    for (PDSignature signatureDictionary : signatureDictionaries) {
            byte[] extractedSignature = signatureDictionary.getContents(FileUtils.readFileToByteArray(file));
            byte[] signedContent = signatureDictionary.getSignedContent(FileUtils.readFileToByteArray(file));

            signature.update(signedContent);
            isVerified = signature.verify(extractedSignature);
    }

但我得到了一个错误:

Signature length not correct: got 3300 but was expecting 512

我根据本文生成了私钥:https://www.baeldung.com/x-509-authentication-in-spring-security
我搜索解决方案并尝试对签名进行base64解码,但出现以下错误:

Illegal base64 character -7e

签名初始化:

Signature signature = Signature.getInstance("SHA256withRSA");
    PublicKey publicKey = SecurityUtils.getX509FromRequest(request).getPublicKey();
    signature.initVerify(publicKey);

我在猜 SHA256withRSA 算法就是问题所在。我怎样才能解决这个问题?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题