我有一条消息,我想用数字证书在ANDROID中用android-studio签署这些数据。这是我的代码:
List certList = new ArrayList();
//CMSTypedData msg = new CMSProcessableByteArray("Hello world!".getBytes());
certList.add(pCertificate);
Store certs = new JcaCertStore(certList);
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
ContentSigner sha1Signer = new JcaContentSignerBuilder(gen.DIGEST_SHA1).setProvider("SC").build((PrivateKey) keyStore.getKey(alias, "zara2008".toCharArray()));
gen.addSignerInfoGenerator(
new JcaSignerInfoGeneratorBuilder(
new JcaDigestCalculatorProviderBuilder().setProvider("SC").build())
.build(sha1Signer, pCertificate));
gen.addCertificates(certs );
// Add the data (XML) to the Message
String dstdn = "cn=wsaahomo,o=afip,c=ar,serialNumber=CUIT 33693450239";
String LoginTicketRequest_xml;
LoginTicketRequest_xml = LoginTicket.create_LoginTicketRequest(SignerDN, dstdn, "wsfe", (long) 3600);
CMSProcessable data = new CMSProcessableByteArray(LoginTicketRequest_xml.getBytes());
CMSTypedData datatyped = new CMSProcessableByteArray(LoginTicketRequest_xml.getBytes());
CMSSignedData sigData = gen.generate(datatyped, false);
错误为:“请求的签名类型未知: 1.3.14.3.2.26”
我尝试了不同的解决方案,比如put "DIGEST_SHA1“,但不起作用。
我尝试在安卓中使用BouncyCastle (我运行了一些我在其他地方找到的脚本,使BC可以在安卓中工作)。它给了我很多“弃用”的信息。
// Create a new empty CMS Message
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
// Add a Signer to the Message
gen.addSigner(pKey, pCertificate, CMSSignedDataGenerator.DIGEST_SHA1);
// Add the Certificate to the Message
gen.addCertificatesAndCRLs(cstore);
// Add the data (XML) to the Message
CMSProcessable data = new CMSProcessableByteArray(LoginTicketRequest_xml.getBytes());
// Add a Sign of the Data to the Message
CMSSignedData signed = gen.generate(data, true, "BC");
//
asn1_cms = signed.getEncoded();但这不是一个解决方案,我不想使用过时的代码。
发布于 2015-03-20 01:40:34
Afip不支持Android连接。尝试使用wcf服务,并在服务器上安装已认证的。
https://stackoverflow.com/questions/27308621
复制相似问题