- Posts: 21
- Thank you received: 1
Microsoft Windows Phone 8.1 support ends (13 Jul 2017)
Microsoft has ended support for Windows Phone 8.1
Questions about Android development and PDF
Encryption and Decryption
- manderin87
- Topic Author
- Offline
- Junior Member
-
Less
More
IP: 192.168.0.71
11 years 10 months ago - 11 years 10 months ago #7007
by manderin87
Encryption and Decryption was created by manderin87
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.
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
I am overriding the PDFAESStream class and attempting to input my own decryption method, but it is not working.
Code:
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
Last edit: 11 years 10 months ago by jstampe.
- manderin87
- Topic Author
- Offline
- Junior Member
-
Less
More
- Posts: 21
- Thank you received: 1
IP: 192.168.0.71
11 years 10 months ago #7052
by manderin87
Replied by manderin87 on topic Encryption and Decryption
Any ideas?
thanks
thanks
IP: 192.168.0.71
11 years 10 months ago #7059
by radaee
Replied by radaee on topic Encryption and Decryption
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();
//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();
- manderin87
- Topic Author
- Offline
- Junior Member
-
Less
More
- Posts: 21
- Thank you received: 1
IP: 192.168.0.71
11 years 10 months ago #7064
by manderin87
Replied by manderin87 on topic Encryption and Decryption
Is it possible to encrypt outside the library and decrypt when opening the pdf?
IP: 192.168.0.158
11 years 10 months ago #7065
by nermeen
Replied by nermeen on topic Encryption and Decryption
yes, as long as it was done using java methods
Time to create page: 0.464 seconds