我有一条消息,我想用数字证书在 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" 但不起作用。
我尝试在 ANDROID 中使用 BouncyCastle(我运行了一些我在其他地方找到的脚本,使 BC 在 Android 中工作)。它给了我很多“已弃用”的消息。
// 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();