【发布时间】:2014-12-05 04:09:57
【问题描述】:
我有一条消息,我想使用数字证书在 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();
【问题讨论】:
-
Cesar,pudiste armar lo que AFIP denomina CMS del tipo “SignedData”? Generé el TRA y la Firma del TRA pero no tengo idea de como mandarlo en loginCms。
-
Si, me pude conectar a la AFIP y obtener el ticket de autorización。 Use las mismas librerías que se usan en el ejemlo que te da la AFIP。 Las descargué y las agregué al proyecto y las use。 En un rato me fijo cómo lo hice。
-
Los Jar 儿子:bcmail,bcprov,y ksoap2-android-assembly。
-
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile files('libs/bcmail2.jar') compile files('libs/bcprov2.jar' ) 编译文件('libs/ksoap2-android-assembly-3.3.0-jar-with-dependencies.jar') }
-
la llamada al ws de la AFIP la hice con la librería ksoap2
标签: android android-studio x509certificate sha1 spongycastle