Changes in / [bb739b0:6f9915f] in dispositivos_moviles


Ignore:
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • .gitignore

    r292b560 r292b560  
    88/TibisayMovil/.classpath
    99/TibisayMovil/gen/*
     10/TibisayMovil/.*
  • TibisayMovil/gen/ve/gob/cenditel/tibisaymovil/R.java

    r0d4fa20 rc14b8d2  
    115115        public static final int TextView01=0x7f0c0078;
    116116        public static final int action_settings=0x7f0c008c;
    117         public static final int archivo_descifrado=0x7f0c0023;
     117        public static final int archivo_descifrado=0x7f0c0024;
    118118        public static final int archivo_original_a_descifrar=0x7f0c0050;
    119119        public static final int archivo_original_a_firmar=0x7f0c0041;
    120120        public static final int archivo_original_pdf=0x7f0c0020;
    121121        public static final int archivo_para_firmar=0x7f0c007e;
    122         public static final int arrow_show_errors=0x7f0c0024;
     122        public static final int arrow_show_errors=0x7f0c0025;
    123123        public static final int button_accept=0x7f0c0007;
    124124        public static final int button_accept_text=0x7f0c0008;
     
    158158        public static final int cert_item_subject=0x7f0c0059;
    159159        public static final int certificate_issuer=0x7f0c004f;
    160         public static final int certificate_list=0x7f0c0026;
     160        public static final int certificate_list=0x7f0c0027;
    161161        public static final int certificate_serial=0x7f0c004a;
    162162        public static final int certificate_to_encrypt_description=0x7f0c0030;
     
    193193        public static final int label_certificate_issuer=0x7f0c004e;
    194194        public static final int label_certificate_serial=0x7f0c0049;
    195         public static final int label_certificate_to_remove=0x7f0c0027;
     195        public static final int label_certificate_to_remove=0x7f0c0028;
    196196        public static final int label_certificate_valid_from=0x7f0c004b;
    197197        public static final int label_certificate_valid_until=0x7f0c004c;
    198198        public static final int label_destinatario_cifrado=0x7f0c002c;
    199         public static final int label_recipient_certificate=0x7f0c0025;
     199        public static final int label_recipient_certificate=0x7f0c0026;
    200200        public static final int layoutSignatureErrors=0x7f0c0044;
    201         public static final int layout_certificate_to_remove=0x7f0c0028;
     201        public static final int layout_certificate_to_remove=0x7f0c0029;
    202202        public static final int layout_decrypted_file_and_arrow=0x7f0c0022;
    203203        public static final int linearLayout=0x7f0c0017;
     
    251251        public static final int title_signature_date_info=0x7f0c0047;
    252252        public static final int title_signature_errors=0x7f0c0042;
    253         public static final int type_image=0x7f0c0029;
     253        public static final int type_image=0x7f0c0023;
    254254        public static final int valid_text=0x7f0c0065;
    255255    }
  • TibisayMovil/res/layout/activity_decryption_result.xml

    re68708b rc14b8d2  
    4242        android:layout_height="wrap_content" >
    4343
     44        <ImageView
     45        android:id="@+id/type_image"
     46        android:layout_width="35dp"
     47        android:layout_height="wrap_content"
     48        android:layout_alignParentLeft="true"
     49        android:layout_centerVertical="true"
     50        android:contentDescription="@string/type"
     51        android:src="@drawable/ic_archivo" />
     52       
    4453        <TextView
    4554                android:id="@+id/archivo_descifrado"
  • TibisayMovil/src/ve/gob/cenditel/tibisaymovil/PDFVerifyResultActivity.java

    re68708b rc14b8d2  
    5555    private LinearLayout button_finish;
    5656
    57  // ruta absoluta al archivo a verificar
     57    // ruta absoluta al archivo a verificar
    5858    private String pdfToVerify;
    5959       
  • TibisayMovil/src/ve/gob/cenditel/tibisaymovil/PKCS12ToDecryptActivity.java

    r647bb1f rc14b8d2  
    1313import java.util.Collections;
    1414import java.util.Date;
     15import java.util.Vector;
     16
     17import com.lowagie.text.pdf.PdfReader;
    1518
    1619import ee.sk.digidoc.DataFile;
     
    2225import ee.sk.xmlenc.EncryptedData;
    2326import ee.sk.xmlenc.factory.EncryptedDataParser;
    24 
    2527import ve.gob.cenditel.tibisaymovil.R;
    2628import android.app.Activity;
    2729import android.app.AlertDialog;
    2830import android.app.Dialog;
     31import android.app.ProgressDialog;
    2932import android.content.Context;
    3033import android.content.DialogInterface;
     
    3235import android.graphics.drawable.Drawable;
    3336import android.net.Uri;
     37import android.os.AsyncTask;
    3438import android.os.Bundle;
    3539import android.os.Environment;
     40import android.os.Looper;
    3641import android.util.Log;
    3742import android.view.LayoutInflater;
     
    655660                AlertDialog dialogDetails = null;
    656661               
    657                 AlertDialog.Builder dialogbuilder = new AlertDialog.Builder(this);
     662                final AlertDialog.Builder dialogbuilder = new AlertDialog.Builder(this);
    658663                dialogbuilder.setTitle(R.string.title_pkcs12_password);
    659664                dialogbuilder.setView(dialogview);
     
    669674                    public void onClick(View v) {
    670675                     
    671                      Toast.makeText(PKCS12ToDecryptActivity.this,"  Password : "+ password.getText().toString(), Toast.LENGTH_LONG).show();
     676                     
    672677                     
    673678                     // asignar la contrasena
    674679                     pkcs12Password = password.getText().toString();
     680                     if (!pkcs12Password.isEmpty()){
     681                         //Toast.makeText(PKCS12ToDecryptActivity.this,"PKCS12 Password : "+ password.getText().toString(), Toast.LENGTH_LONG).show();
     682                         
     683                         password.setText("");
     684                         
     685                             // ejecutar el proceso de descifrado.
     686                             decryptFile(fileToDecrypt, pkcs12File, pkcs12Password);
     687
     688                         
     689                     }
    675690                     
    676691                     // ejecutar el proceso de descifrado.
    677                      decryptFile(fileToDecrypt, pkcs12File, pkcs12Password);
     692                     //decryptFile(fileToDecrypt, pkcs12File, pkcs12Password);
    678693                     
    679694                     // borrar el contenido de pkcs12Password
     
    691706       
    692707        /**
    693      * Crea dialogo para obtener la contrasena del archivo P12
     708     * Descifra el archivo pasado como argumento con el archivo P12
    694709     *
    695      * @return Dialog
     710     * @return void
    696711     */
    697         private void decryptFile(String fileToDecrypt, String pkcs12File, String pkcs12Password) {
     712        private void decryptFile(final String fileToDecrypt, final String pkcs12File, final String pkcs12Password) {
    698713               
    699714                Toast.makeText(getApplicationContext(), "Decrypting file: " + fileToDecrypt, Toast.LENGTH_SHORT).show();
    700715               
    701                
     716                // -----------------------------
     717                AsyncTask<Void, Void, ArrayList<String>> task = new AsyncTask<Void, Void, ArrayList<String>>() {
     718
     719            private ProgressDialog pd;
     720
     721            @Override
     722            protected void onPreExecute() {
     723
     724                     pd = new ProgressDialog(PKCS12ToDecryptActivity.this);     
     725                     pd.setTitle("Descifrando archivo");       
     726                     pd.setMessage(getString(R.string.por_favor_epsere));       
     727                     pd.setCancelable(false);   
     728                     pd.setIndeterminate(true);
     729                     pd.show();
     730
     731            }
     732
     733            @Override
     734            protected ArrayList<String> doInBackground(Void... arg0) {
     735
     736                /*
     737                try {
     738                    Thread.sleep(3000);
     739                } catch(InterruptedException ex) {
     740                    Thread.currentThread().interrupt();
     741                }
     742                */
     743               
     744                // para solventar error:
     745                // Can't create handler inside thread that has not called Looper.prepare()
     746                Looper.prepare();
     747               
     748                // arreglo para almacenar resultado de la operacion
     749                ArrayList<String> resultArray = new ArrayList<String>();
     750                resultArray.clear();
     751               
     752                ConfigManager.init("jar://jdigidoc.cfg");
     753                        // signed doc object if used
     754                SignedDoc m_sdoc;
     755                m_sdoc = null;
     756
     757                // encrypted data object if used
     758                EncryptedData m_cdoc;
     759                m_cdoc = null;
     760                       
     761                        String outFile = null, keystoreFile = null, keystorePasswd = null, keystoreType="PKCS12";
     762
     763                        keystoreFile = pkcs12File;
     764
     765                        keystorePasswd = pkcs12Password;
     766
     767                        Log.d("Reading encrypted file: ",  fileToDecrypt);
     768                       
     769                        try {
     770                                EncryptedDataParser dencFac =  ConfigManager.instance().getEncryptedDataParser();
     771                                m_cdoc = dencFac.readEncryptedData(fileToDecrypt);                             
     772                        } catch(Exception ex) {                 
     773                                System.err.println("ERROR: reading encrypted file: " + fileToDecrypt + " - " + ex);
     774                                Log.d("ERROR: reading encrypted file: ",  ex.getMessage());
     775                                ex.printStackTrace(System.err);
     776                                Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_SHORT).show();
     777                               
     778                                //showDialog("Error:", ex.getMessage(), false);
     779                                //return null;
     780                               
     781                                resultArray.add("false");
     782                                resultArray.add("Error");
     783                                resultArray.add(ex.getMessage());
     784                                return resultArray;
     785                        }
     786                       
     787                        int nKey = -1;
     788                       
     789                        try{
     790                               
     791                                Pkcs12SignatureFactory p12fac = new Pkcs12SignatureFactory();
     792                                p12fac.init();
     793                                System.out.println("p12fac.init " );
     794                               
     795                                p12fac.load(keystoreFile, keystoreType, keystorePasswd);
     796                                System.out.println("p12fac.load()");
     797                               
     798                                X509Certificate cert = p12fac.getAuthCertificate(0, keystorePasswd);
     799                                System.out.println("p12fac.getAuthCertificate: " + nKey);
     800                               
     801                                nKey = m_cdoc.getRecvIndex(cert);
     802                                System.out.println("Using recipient: " + nKey);
     803                                if (nKey == -1) {
     804                                        throw(new ArrayIndexOutOfBoundsException(""));
     805                                }
     806                               
     807                               
     808                        } // fin del try interno
     809                        catch(DigiDocException ex){
     810                                System.err.println("ERROR: finding cdoc recipient: " + ex);
     811                               
     812                                Log.d("Error finding cdoc recipient: ",  ex.getMessage());
     813                        ex.printStackTrace(System.err);
     814                        Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_SHORT).show();   
     815                                       
     816                       
     817                       
     818                        if (ex.getCode() == DigiDocException.ERR_TOKEN_LOGIN) {
     819                               
     820                                // el pasword del PKCS12 no es correcto
     821                                //showDialog(getResources().getString(R.string.msg_encryption_error), "password incorrecto", false);
     822                                //return null;
     823                               
     824                                resultArray.add("false");
     825                                resultArray.add(getResources().getString(R.string.msg_encryption_error));
     826                                resultArray.add("contraseña incorrecta.");
     827                                return resultArray;
     828                               
     829                               
     830                        }else{
     831                        //showDialog(getResources().getString(R.string.msg_encryption_error), ex.getMessage(), false);
     832                                //return null;
     833                               
     834                                resultArray.add("false");
     835                                resultArray.add(getResources().getString(R.string.msg_encryption_error));
     836                                resultArray.add(ex.getMessage());
     837                                return resultArray;
     838                        }
     839                       
     840                        } catch(ArrayIndexOutOfBoundsException ex) {
     841                                //showDialog(getResources().getString(R.string.msg_encryption_error),
     842                                //              getResources().getString(R.string.error_decrypting_file_index_out_of_bounds), false);
     843                                //return null;
     844                               
     845                                resultArray.add("false");
     846                                resultArray.add(getResources().getString(R.string.msg_encryption_error));
     847                                resultArray.add(getResources().getString(R.string.error_decrypting_file_index_out_of_bounds));
     848                                return resultArray;
     849                               
     850                        }
     851                       
     852                        System.err.println("**** antes de ejecutar operacion m_cdoc.decryptPkcs12(nKey, keystoreFile, keystorePasswd, keystoreType)");
     853                        // ejecutar la operacion de descifrado:
     854                        try {
     855                               
     856                                m_cdoc.decryptPkcs12(nKey, keystoreFile, keystorePasswd, keystoreType);
     857                               
     858                                String [] absolutePathOriginalFile = fileToDecrypt.split(".cdoc");
     859                                //String fileName = split[0];
     860                                outFile = absolutePathOriginalFile[0];
     861                               
     862                                String [] path = absolutePathOriginalFile[0].split("/");
     863                               
     864                                String originalFileName = path[path.length-1];
     865                               
     866                                FileOutputStream fos = new FileOutputStream( outFile );
     867                               
     868                                Log.d("Decrypting file", "antes de escribir archivo " + outFile);
     869                       
     870                        fos.write(m_cdoc.getData());
     871                       
     872                        Log.d("Decrypting file", "despues de escribir archivo " + outFile);
     873                       
     874                        fos.close();
     875                       
     876                        Log.d("Decrypting file", "despues de cerrar archivo " + outFile);
     877                       
     878                        DigiDocFactory digFac = ConfigManager.instance().getDigiDocFactory();
     879                        Log.d("Decrypting file", "despues ConfigManager.instance().getDigiDocFactory()");               
     880                       
     881                        File file = new File(outFile);
     882                        InputStream selectedFile = null;
     883                        selectedFile = new BufferedInputStream(new FileInputStream(file));
     884                       
     885                        m_sdoc = digFac.readSignedDocFromStreamOfType(selectedFile, false);
     886                        Log.d("----", "leyo el ddoc");
     887                        Toast.makeText(getApplicationContext(), "leyó el ddoc", Toast.LENGTH_SHORT).show();
     888                       
     889                        selectedFile.close();
     890
     891                        // *******
     892                        Log.d("Decrypting file", "antes de m_sdoc.getDataFile(0)");
     893                        DataFile df = m_sdoc.getDataFile(0);
     894                        Log.d("Decrypting file", "despues de m_sdoc.getDataFile(0)");
     895                       
     896                        String decryptedDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" +
     897                                getResources().getString(R.string.app_name) + "/" +
     898                                getResources().getString(R.string.decrypted_dir_files) + "/";
     899                       
     900                        decryptedFile = decryptedDir+originalFileName;
     901                       
     902                        fos = new FileOutputStream(decryptedFile);
     903                        InputStream is = df.getBodyAsStream();
     904                       
     905                        if(is == null) {
     906                        System.err.println("DataFile has no data!");
     907                        //showDialog(getResources().getString(R.string.msg_encryption_error),
     908                        //              "DataFile has no data!", false);
     909                        //return null;
     910                       
     911                       
     912                        resultArray.add("false");
     913                                resultArray.add(getResources().getString(R.string.msg_encryption_error));
     914                                resultArray.add("DataFile has no data!");
     915                                return resultArray;
     916                       
     917                    }
     918                        byte[] data = new byte[4096];
     919                    int n = 0, m = 0;
     920                    while((n = is.read(data)) > 0) {
     921                        fos.write(data, 0, n);
     922                        m += n;
     923                    }
     924                    fos.close();
     925                    is.close();
     926
     927                    // borrar el archivo ddoc
     928                    File ddocFile = new File(outFile);
     929                    ddocFile.delete();
     930                   
     931                   
     932                    //Toast.makeText(getApplicationContext(), "Descifrado correctamente: " + decryptedFile, Toast.LENGTH_SHORT).show();
     933                        //showDialog("Información:", "Archivo descifrado exitosamente.", true);
     934                   
     935                    resultArray.add("true");
     936                                resultArray.add("Información:");
     937                                resultArray.add("Archivo descifrado exitosamente.");
     938                       
     939                               
     940                               
     941                        } catch (DigiDocException e) {
     942                               
     943                                //showDialog(getResources().getString(R.string.msg_encryption_error),
     944                                //              e.getMessage(), false);
     945                                //return null;
     946                               
     947                                resultArray.add("false");
     948                                resultArray.add(getResources().getString(R.string.msg_encryption_error));
     949                                resultArray.add(e.getMessage());
     950                                return resultArray;
     951                               
     952                        }
     953                       
     954                        catch (FileNotFoundException e) {
     955                                //showDialog(getResources().getString(R.string.msg_encryption_error),
     956                                //              e.getMessage(), false);
     957                                //return null;
     958                               
     959                                resultArray.add("false");
     960                                resultArray.add(getResources().getString(R.string.msg_encryption_error));
     961                                resultArray.add(e.getMessage());
     962                                return resultArray;
     963                               
     964                        } catch (IOException e) {
     965                                //showDialog(getResources().getString(R.string.msg_encryption_error),
     966                                //              e.getMessage(), false);
     967                                //return null;
     968                               
     969                                resultArray.add("false");
     970                                resultArray.add(getResources().getString(R.string.msg_encryption_error));
     971                                resultArray.add(e.getMessage());
     972                                return resultArray;
     973                               
     974                        }
     975                               
     976                return resultArray;
     977         }           
     978         @Override
     979         protected void onPostExecute(ArrayList<String> result) {
     980                 
     981                 if (result.get(0).equals("false")){
     982                         showDialog(result.get(1), result.get(2), false);
     983                 }else{
     984                         showDialog(result.get(1), result.get(2), true);
     985                 }
     986                         
     987
     988             pd.dismiss();
     989
     990         }
     991
     992        };
     993
     994        task.execute((Void[])null);
     995               
     996               
     997                // -----------------------------
     998/*             
    702999                ConfigManager.init("jar://jdigidoc.cfg");
    703                 /** signed doc object if used */
     1000                // signed doc object if used
    7041001        SignedDoc m_sdoc;
    7051002        m_sdoc = null;
    7061003
    707         /** encrypted data object if used */
     1004        // encrypted data object if used
    7081005        EncryptedData m_cdoc;
    7091006        m_cdoc = null;
     
    8751172                        return;
    8761173                }
    877                
     1174*/             
    8781175               
    8791176               
  • TibisayMovil/src/ve/gob/cenditel/tibisaymovil/SelectCertificateToEncryptActivity.java

    rfd4a5b9 rc14b8d2  
    1414import ee.sk.xmlenc.EncryptedData;
    1515import ee.sk.xmlenc.EncryptedKey;
    16 
    1716import ve.gob.cenditel.tibisaymovil.R;
    1817import android.app.Activity;
    1918import android.app.AlertDialog;
     19import android.app.ProgressDialog;
    2020import android.content.Context;
    2121import android.content.DialogInterface;
     
    2323import android.graphics.drawable.Drawable;
    2424import android.net.Uri;
     25import android.os.AsyncTask;
    2526import android.os.Bundle;
    2627import android.os.Environment;
     28import android.os.Looper;
    2729import android.util.Log;
    2830import android.view.LayoutInflater;
     
    495497     */
    496498        // funcion para desplegar el gestor de certificados de destinatarios para cifrar
    497         private void encryptFile(String fileToEncrypt, String certificateToEncrypt) {
     499        private void encryptFile(final String fileToEncrypt, final String certificateToEncrypt) {
    498500               
    499501                Toast.makeText(getApplicationContext(), "Encrypting file: " + fileToEncrypt, Toast.LENGTH_SHORT).show();
    500        
    501                 // TODO chequear que se pueda escribir en el directorio /mnt/sdcard/TibisayMovil/EncryptedFiles
     502               
     503               
    502504                // chequear disponibilidad de directorio de certificados
    503505            if (!checkCertificatesDirectoryAvailability()){
     
    508510            }
    509511               
    510                
     512                // ********************* prueba de AsyncTask ******************************
     513               
     514                AsyncTask<Void, Void, ArrayList<String>> task = new AsyncTask<Void, Void, ArrayList<String>>() {
     515
     516            private ProgressDialog pd;
     517
     518            @Override
     519            protected void onPreExecute() {
     520
     521                     pd = new ProgressDialog(SelectCertificateToEncryptActivity.this); 
     522                     pd.setTitle("Cifrando archivo");   
     523                     pd.setMessage(getString(R.string.por_favor_epsere));       
     524                     pd.setCancelable(false);   
     525                     pd.setIndeterminate(true);
     526                     pd.show();
     527
     528            }
     529
     530            @Override
     531            protected ArrayList<String> doInBackground(Void... arg0) {
     532           
     533                /*
     534                try {
     535                    Thread.sleep(3000);
     536                } catch(InterruptedException ex) {
     537                    Thread.currentThread().interrupt();
     538                }
     539                */
     540               
     541                // para solventar error:
     542                // Can't create handler inside thread that has not called Looper.prepare()
     543                Looper.prepare();
     544               
     545                // arreglo para almacenar resultado de la operacion
     546                ArrayList<String> resultArray = new ArrayList<String>();
     547                resultArray.clear();
     548               
     549               
     550                ConfigManager.init("jar://jdigidoc.cfg");
     551                        Log.d("despues de:", "ConfigManager.init");
     552               
     553                // signed doc object if used
     554                SignedDoc m_sdoc;
     555                m_sdoc = null;
     556
     557                // encrypted data object if used
     558                EncryptedData m_cdoc;
     559                m_cdoc = null;
     560               
     561                String inFile = null, outFile = null;
     562                String certFile = null;
     563                String recipient = null;
     564                String keyName = null;
     565                String carriedKeyName = null;
     566                String sId = null;     
     567                       
     568                inFile = fileToEncrypt;
     569                certFile = certificateToEncrypt;
     570               
     571                // agregar el destinatario
     572                try {
     573
     574                        if (m_cdoc == null){
     575                                Log.d("m_cdoc == null", "-");
     576                                m_cdoc = new EncryptedData(null, null, null, EncryptedData.DENC_XMLNS_XMLENC, EncryptedData.DENC_ENC_METHOD_AES128);
     577                        }
     578                        Log.d("Adding recipient", certFile);
     579                        X509Certificate recvCert = SignedDoc.readCertificate(new File(certFile));
     580                        if (recvCert != null && recipient == null)
     581                                recipient = SignedDoc.getCommonName(recvCert.getSubjectDN().getName());
     582                        Log.d("Recipient", recipient);
     583                        if (sId == null){
     584                                int n = m_cdoc.getNumKeys() + 1;
     585                                sId = "ID" + n;
     586                               
     587                        }
     588                       
     589                        EncryptedKey ekey = new EncryptedKey(sId, recipient, EncryptedData.DENC_ENC_METHOD_RSA1_5, keyName, carriedKeyName, recvCert);
     590                        m_cdoc.addEncryptedKey(ekey);
     591
     592                       
     593                }catch(Exception e){
     594                        Log.d("Error adding EncryptedKey: ", e.getMessage());
     595                        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
     596                       
     597                        //showDialog(getResources().getString(R.string.msg_encryption_error), e.getMessage());
     598                        //return;
     599                       
     600                        resultArray.add("false");
     601                                resultArray.add(getResources().getString(R.string.msg_encryption_error));
     602                                resultArray.add(e.getMessage());
     603                                return resultArray;
     604                }
     605               
     606                // ejecutar el cifrado
     607                try {
     608
     609                        Log.d("Encrypting file:", inFile + " to: " + outFile);
     610                        File fIn = new File(inFile);
     611                        // create a ddoc intermediate file
     612                        m_sdoc = new SignedDoc(SignedDoc.FORMAT_DIGIDOC_XML, SignedDoc.VERSION_1_3);
     613                       
     614                        Log.d("Encrypting file:", "paso new SignedDoc");
     615                       
     616                        DataFile df = m_sdoc.addDataFile(new File(inFile), SignedDoc.xmlns_digidoc13, DataFile.CONTENT_EMBEDDED_BASE64);
     617                                       
     618                        Log.d("Encrypting file:", "paso addDataFile");
     619                       
     620                       
     621                        byte[] data = SignedDoc.readFile(new File(inFile));
     622                       
     623                        Log.d("Encrypting file:", "paso readFile");
     624                       
     625                        df.setBase64Body(data);
     626                       
     627                        Log.d("Encrypting file:", "paso setBase64Body");
     628                       
     629                        byte[] inData = m_sdoc.toXML().getBytes("UTF-8");
     630                       
     631                        Log.d("Encrypting file:", "paso toXML()");
     632                       
     633                        Log.d("Encrypting file", "Content: " + inFile + " size: " + data.length);
     634                        Log.d("Encrypting file", "DF: " + new String(inData));
     635                       
     636                        m_cdoc.setData(inData);
     637                        m_cdoc.setDataStatus(EncryptedData.DENC_DATA_STATUS_UNENCRYPTED_AND_NOT_COMPRESSED);
     638                        m_cdoc.addProperty(EncryptedData.ENCPROP_FILENAME, inFile + ".ddoc");
     639                        m_cdoc.setMimeType(EncryptedData.DENC_ENCDATA_TYPE_DDOC);
     640                        StringBuffer sb = new StringBuffer();
     641                        sb.append(fIn.getName());
     642                        sb.append("|");
     643                        sb.append(new Long(fIn.length()).toString() + " B|");
     644                        sb.append("application/unknown|");
     645                        sb.append("/" + fIn.getName());
     646                        m_cdoc.addProperty(EncryptedData.ENCPROP_ORIG_FILE, sb.toString());
     647                        //m_cdoc.addProperty(EncryptedData.ENCPROP_ORIG_SIZE, new Long(inData.length).toString());
     648                       
     649                        int nCompressOption = 0;
     650                       
     651                        m_cdoc.encrypt(nCompressOption);
     652                                       
     653                        // genera el archivo cifrado en /data/data/ve.gob.cenditel/files
     654                        //FileOutputStream fos = openFileOutput(outFile, Context.MODE_WORLD_WRITEABLE);
     655                       
     656                        outFile = encrypted_dir_files + fIn.getName()+".cdoc";
     657                        Toast.makeText(getApplicationContext(), "outFile: " + outFile, Toast.LENGTH_SHORT).show();
     658                       
     659                       
     660                        FileOutputStream fos = new FileOutputStream( outFile );
     661                       
     662                        Log.d("Encrypting file", "antes de escribir archivo " + outFile);
     663                       
     664                        fos.write(m_cdoc.toXML());
     665                       
     666                        Log.d("Encrypting file", "despues de escribir archivo " + outFile);
     667                       
     668                        fos.close();
     669                       
     670                        Log.d("Encrypting file", "despues de cerrar archivo " + outFile);
     671                       
     672                        Toast.makeText(getApplicationContext(), "Cifrado correctamente: " + outFile, Toast.LENGTH_SHORT).show();
     673                       
     674                        // lanzar la actividad para mostrar el resultado del cifrado
     675                        //showEncryptionResults(fileToEncrypt, outFile, recipient);             
     676                        resultArray.add("true"); // [0]
     677                        resultArray.add(outFile); // [1]
     678                        resultArray.add(recipient); // [2]
     679
     680
     681                } catch(Exception e) {
     682                        Log.d("Error encrypting file: ", inFile + " - " + e.getMessage());
     683                        e.printStackTrace(System.err);
     684                        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
     685                       
     686                        //showDialog(getResources().getString(R.string.msg_encryption_error), e.getMessage());
     687                        //return;
     688                       
     689                        resultArray.add("false");
     690                                resultArray.add(getResources().getString(R.string.msg_encryption_error));
     691                                resultArray.add(e.getMessage());
     692                                return resultArray;
     693                       
     694                }               
     695               
     696                return resultArray;
     697            }
     698           
     699            @Override
     700            protected void onPostExecute(ArrayList<String> result) {
     701                 
     702               
     703                        if (result.get(0).equals("false")){
     704                                showDialog(result.get(1), result.get(2));
     705                        }else{
     706                                //showDialog(result.get(1), result.get(2), true);
     707                                showEncryptionResults(fileToEncrypt, result.get(1), result.get(2));
     708                        }
     709                               
     710                pd.dismiss();
     711            }
     712                       
     713                };
     714               
     715                task.execute((Void[])null);
     716               
     717                // ********************* fin prueba de AsyncTask ******************************
     718       
     719/*             
    511720        ConfigManager.init("jar://jdigidoc.cfg");
    512721                Log.d("despues de:", "ConfigManager.init");
    513722       
    514         /** signed doc object if used */
     723        // signed doc object if used
    515724        SignedDoc m_sdoc;
    516725        m_sdoc = null;
    517726
    518         /** encrypted data object if used */
     727        // encrypted data object if used
    519728        EncryptedData m_cdoc;
    520729        m_cdoc = null;
     
    640849        // lanzar la actividad para mostrar el resultado del cifrado
    641850        showEncryptionResults(fileToEncrypt, outFile, recipient);
    642        
     851*/     
    643852       
    644853               
     
    775984                });
    776985               
    777                 // 3. Get the AlertDialog from create()                         
     986                // 3. Get the AlertDialog from create()
    778987                AlertDialog dialog = builder.create();
    779988                dialog.show();         
Note: See TracChangeset for help on using the changeset viewer.