0

I have a message and I want to sign that data with a digital certificate, in ANDROID, with android-studio. 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"

I tryed distints solutions, like put "DIGEST_SHA1" but doesn't works.

I tryed with BouncyCastle in ANDROID (I run some script that I found elsewhere that makes that BC works in 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.

1 Answers1

0

Afip don't have support for Android Connection. Try with wcf service and the certified installed in the server.

Jsperk
  • 124
  • 1
  • 11
  • Amigo no estoy preguntando si afip tiene soporte para Android. Releé que ahi puse que me pude conectar a la AFIP pero usando librerías que están obsoletas. – César Javier Mendoza Mar 19 '15 at 18:14
  • I'm not asking if AFIP has support for Android . Please read the post 3 or 4 times until you can understand THAT I CONNECT SUCCESFULLY WITH AFIP BUT WITH OBSOLETES LIBRARIES. – César Javier Mendoza Mar 20 '15 at 03:43