简体   繁体   English

SpongyCastle:如何生成签名数据?

[英]SpongyCastle: how to generate signed data?

I have a message and I want to sign that data with a digital certificate, in ANDROID, with android-studio. 我有一条消息,我想用Android Studio中的ANDROID数字证书对该数据进行签名。 This my code: 这是我的代码:

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

This is the error: "Unknown signature type requested: 1.3.14.3.2.26" 这是错误:“请求的未知签名类型:1.3.14.3.2.26”

I tryed distints solutions, like put "DIGEST_SHA1" but doesn't works. 我尝试了distints解决方案,例如放了“ DIGEST_SHA1”,但不起作用。

I tryed with BouncyCastle in ANDROID (I run some script that I found elsewhere that makes that BC works in Android). 我在ANDROID中尝试了BouncyCastle(我运行了一些我在其他地方找到的脚本,使BC在Android中工作)。 It's gives me a lot of messages "deprecated". 它给了我很多“不赞成使用”的信息。

  // 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(); 
But this is not a solution, I dont want to work with deprecated code. 但这不是解决方案,我不想使用不推荐使用的代码。

Afip don't have support for Android Connection. Afip不支持Android Connection。 Try with wcf service and the certified installed in the server. 尝试使用wcf服务并将认证的服务器安装在服务器中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM