错误“内容格式错误。”在签名验证

问题描述 投票:0回答:1

我想验证我的签名。我的签名是一个字节数组。我用海绵城堡

我收到错误:

“org.spongycastle.cms.CMSException:内容格式错误。”

这是我的代码:

String base64 = Base64.toBase64String(signedchallenge);
CMSSignedData cms = new CMSSignedData(Base64.decode(base64));
Store store = cms.getCertificates();
SignerInformationStore signers = cms.getSignerInfos();
Collection c = signers.getSigners();

我在行中遇到错误:

“CMSSignedData cms =新CMSSignedData(Base64.decode(base64));”

我也使用这种方法来生成签名挑战。我是在智能购物车里做的

Signature signature=Signature.getInstance(Signature.ALG_RSA_SHA_PKCS1,false);
signature.init(thePrivateKey,Signature.MODE_SIGN);
signLength=signature.sign(buffer,(short)(ISO7816.OFFSET_CDATA & 0xFF), inputlength, buffer, (short)(0));
apdu.setOutgoingAndSend((short)0,signLength);
android digital-signature bouncycastle smartcard contactless-smartcard
1个回答
1
投票

根据javacard文档

ALG_RSA_SHA_PKCS1
生成 20 字节的 SHA 摘要,根据 PKCS#1 (v1.5) 方案填充摘要,并使用 RSA 对其进行加密

要验证 Android 端的签名,请使用此代码

Signature sig = Signature.getInstance("SHA1withRSA");
sig.initVerify(publicKey);
sig.update(challenge);
boolean verifies = sig.verify(signedchallenge);

其中signedchallenge是

buffer
上从
(short)(ISO7816.OFFSET_CDATA & 0xFF)
signLength
可用的签名,
challenge
是要签名的原始数据

© www.soinside.com 2019 - 2024. All rights reserved.