Encryption and Decryption - RadaeePDF.com
Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
13 Jul 2017
Microsoft has ended support for Windows Phone 8.1
Read More...
Questions about Android development and PDF
  • Page:
  • 1

TOPIC: Encryption and Decryption

Encryption and Decryption 4 years 2 months ago #7007

  • manderin87
  • manderin87's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 21
  • Thank you received: 1
I am attempting to encrypt a pdf and then display it in the reader.

I am overriding the PDFAESStream class and attempting to input my own decryption method, but it is not working.
MessageDigest sha = MessageDigest.getInstance("SHA-1");
key = sha.digest(key);
key = Arrays.copyOf(key, 16);
SecretKeySpec skey = new SecretKeySpec(key, "AES");  
byte[] ivbytes = new byte[] { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 };
IvParameterSpec iv = new IvParameterSpec(ivbytes);//need IV in CBC mode
m_dec_cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
m_dec_cipher.init(Cipher.DECRYPT_MODE, skey, iv);
m_enc_cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
m_enc_cipher.init(Cipher.ENCRYPT_MODE, skey, iv);

This does not work and I get a -3 error when opening the stream.

I am using the Secure.getString(context().getContentResolver(),Secure.ANDROID_ID).getBytes(UTF8) method to generate the 16 byte key after encoding it to SHA-1 and pulling out the first 16 bytes.

Can this work? What is wrong with the encryption?
thanks

Please Log in or Create an account to join the conversation.

Last edit: by jstampe.

Encryption and Decryption 4 years 2 months ago #7052

  • manderin87
  • manderin87's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 21
  • Thank you received: 1
Any ideas?

thanks

Please Log in or Create an account to join the conversation.

Encryption and Decryption 4 years 2 months ago #7059

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 846
  • Karma: 43
  • Thank you received: 12
there are simple codes in PDFTestAct
//byte key[] = new byte[16];
//stream.open("/sdcard/ttt.pdf", key);//pdf file to encrypt.
//stream.ImportFromFile("/sdcard/test.pdf");//import test.pdf and encrypt to ttt.pdf
//stream.ExportToFile("/sdcard/test1.pdf");//decrypt to test1.pdf
//stream.close();

Please Log in or Create an account to join the conversation.

Encryption and Decryption 4 years 2 months ago #7064

  • manderin87
  • manderin87's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 21
  • Thank you received: 1
Is it possible to encrypt outside the library and decrypt when opening the pdf?

Please Log in or Create an account to join the conversation.

Encryption and Decryption 4 years 2 months ago #7065

  • nermeen
  • nermeen's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 865
  • Karma: 23
  • Thank you received: 70
yes, as long as it was done using java methods

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Powered by Kunena Forum