Changeset c14b8d2 in dispositivos_moviles for TibisayMovil/src/ve/gob
- Timestamp:
- Nov 1, 2013, 10:34:18 AM (11 years ago)
- Branches:
- master
- Children:
- 58c7f6a
- Parents:
- f32914c
- Location:
- TibisayMovil/src/ve/gob/cenditel/tibisaymovil
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TibisayMovil/src/ve/gob/cenditel/tibisaymovil/PDFVerifyResultActivity.java
re68708b rc14b8d2 55 55 private LinearLayout button_finish; 56 56 57 // ruta absoluta al archivo a verificar57 // ruta absoluta al archivo a verificar 58 58 private String pdfToVerify; 59 59 -
TibisayMovil/src/ve/gob/cenditel/tibisaymovil/PKCS12ToDecryptActivity.java
rf32914c rc14b8d2 679 679 pkcs12Password = password.getText().toString(); 680 680 if (!pkcs12Password.isEmpty()){ 681 Toast.makeText(PKCS12ToDecryptActivity.this,"PKCS12 Password : "+ password.getText().toString(), Toast.LENGTH_LONG).show();681 //Toast.makeText(PKCS12ToDecryptActivity.this,"PKCS12 Password : "+ password.getText().toString(), Toast.LENGTH_LONG).show(); 682 682 683 683 password.setText(""); -
TibisayMovil/src/ve/gob/cenditel/tibisaymovil/SelectCertificateToEncryptActivity.java
rfd4a5b9 rc14b8d2 14 14 import ee.sk.xmlenc.EncryptedData; 15 15 import ee.sk.xmlenc.EncryptedKey; 16 17 16 import ve.gob.cenditel.tibisaymovil.R; 18 17 import android.app.Activity; 19 18 import android.app.AlertDialog; 19 import android.app.ProgressDialog; 20 20 import android.content.Context; 21 21 import android.content.DialogInterface; … … 23 23 import android.graphics.drawable.Drawable; 24 24 import android.net.Uri; 25 import android.os.AsyncTask; 25 26 import android.os.Bundle; 26 27 import android.os.Environment; 28 import android.os.Looper; 27 29 import android.util.Log; 28 30 import android.view.LayoutInflater; … … 495 497 */ 496 498 // 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) { 498 500 499 501 Toast.makeText(getApplicationContext(), "Encrypting file: " + fileToEncrypt, Toast.LENGTH_SHORT).show(); 500 501 // TODO chequear que se pueda escribir en el directorio /mnt/sdcard/TibisayMovil/EncryptedFiles502 503 502 504 // chequear disponibilidad de directorio de certificados 503 505 if (!checkCertificatesDirectoryAvailability()){ … … 508 510 } 509 511 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 /* 511 720 ConfigManager.init("jar://jdigidoc.cfg"); 512 721 Log.d("despues de:", "ConfigManager.init"); 513 722 514 / ** signed doc object if used */723 // signed doc object if used 515 724 SignedDoc m_sdoc; 516 725 m_sdoc = null; 517 726 518 / ** encrypted data object if used */727 // encrypted data object if used 519 728 EncryptedData m_cdoc; 520 729 m_cdoc = null; … … 640 849 // lanzar la actividad para mostrar el resultado del cifrado 641 850 showEncryptionResults(fileToEncrypt, outFile, recipient); 642 851 */ 643 852 644 853 … … 775 984 }); 776 985 777 // 3. Get the AlertDialog from create() 986 // 3. Get the AlertDialog from create() 778 987 AlertDialog dialog = builder.create(); 779 988 dialog.show();
Note: See TracChangeset
for help on using the changeset viewer.