错误“格式错误的内容”。在签名验证中 [英] Error "Malformed content." in Signature Verification

查看:461
本文介绍了错误“格式错误的内容”。在签名验证中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想验证我的签名。我的签名是一个字节数组。我使用海绵城堡
,但出现错误 org.spongycastle.cms.CMSException:内容格式错误。
这是我的代码:

I want to verify my signature . my signature is a byte array. I use spongy castle I get error "org.spongycastle.cms.CMSException: Malformed content." this is my code:

   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))行中出现错误

I get error in line " CMSSignedData cms = new CMSSignedData(Base64.decode(base64));"

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

also I used this method for signed challenge generation. It did in smart cart

          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文档


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

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端验证签名,请使用此代码

To verify the signature in Android side use this code

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

其中的签署挑战是缓冲区上可用的签名从(short)(ISO7816.OFFSET_CDATA& 0xFF) signLength 挑战是要签名的原始数据

Where signedchallenge is the signature available on buffer from (short)(ISO7816.OFFSET_CDATA & 0xFF) to signLength and challenge is the original data to sign

这篇关于错误“格式错误的内容”。在签名验证中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆