签名验证错误 "Malformed content."

Error "Malformed content." in Signature Verification

我想验证我的签名。我的签名是一个字节数组。我用海绵城堡 我收到错误 "org.spongycastle.cms.CMSException: Malformed content." 这是我的代码:

   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 = new 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);

根据javacard documentation

ALG_RSA_SHA_PKCS1 generates a 20-byte SHA digest, pads the digest according to the PKCS#1 (v1.5) scheme, and encrypts it using 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 是要签名的原始数据