错误"格式错误的内容。"在签名验证中

时间:2016-11-21 17:01:49

标签: android digital-signature bouncycastle smartcard contactless-smartcard

我想验证我的签名。我的签名是一个字节数组。我用的是海绵城堡 我收到错误" 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 = 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);

1 个答案:

答案 0 :(得分:1)

根据javacard documentation

  

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

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