We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

AES Decryption issue for Aspose PDF .Net 19.1

Hi there,

I am using Aspose PDF 19.1 with 30-day temporary license.
I am testing the decryption of PDF files encrypted by Adobe Acrobat X with various AES encryption level and user/owner passwords.

This is the code that I am using:

        private void runTest()
        {
            String userOnlyAES128Test1 = @"C:\temp\test-aspose-pdf\1_AES128_user_only_sample.pdf";
            String userOnlyAES128Test2 = @"C:\temp\test-aspose-pdf\2_AES128_user_only_sample.pdf";
            String userOwnerAES128Test3 = @"C:\temp\test-aspose-pdf\3_AES128_user_owner_sample.pdf";
            String userOwnerAES128Test4 = @"C:\temp\test-aspose-pdf\4_AES128_user_owner_sample.pdf";

            String userOnlyAES256Test5 = @"C:\temp\test-aspose-pdf\5_AES256_user_only_sample.pdf";
            String userOnlyAES256Test6 = @"C:\temp\test-aspose-pdf\6_AES256_user_only_sample.pdf";
            String userOwnerAES256Test7 = @"C:\temp\test-aspose-pdf\7_AES256_user_owner_sample.pdf";
            String userOwnerAES256Test8 = @"C:\temp\test-aspose-pdf\8_AES256_user_owner_sample.pdf";

            testDecryption(userOnlyAES128Test1, "user", "1"); // expected: pass, result: pass
            testDecryption(userOnlyAES128Test2, "owner", "2"); // expected: fail, result: fail
            testDecryption(userOwnerAES128Test3, "user", "3"); // expected: fail, result: pass!!
            testDecryption(userOwnerAES128Test4, "owner", "4"); // expected: pass, result: pass

            testDecryption(userOnlyAES256Test5, "user", "5"); // expected: pass, result: pass
            testDecryption(userOnlyAES256Test6, "owner", "6"); // expected: fail, result: fail
            testDecryption(userOwnerAES256Test7, "user", "7"); // expected: fail, result: pass!!
            testDecryption(userOwnerAES256Test8, "owner", "8"); // expected: pass, result: fail!!
        }
		
        private void testDecryption(String fullFileName, String newPassword, String tag)
        {
            String returnMessage;
            try
            {
                Aspose.Pdf.Document document = new Aspose.Pdf.Document(fullFileName, newPassword);
                document.Decrypt();
                document.Save(fullFileName);
                returnMessage = tag + ":" + fullFileName + " has been decrypted with password successfully";
            }
            catch (Aspose.Pdf.InvalidPasswordException e1)
            {
                returnMessage = tag + ":" + fullFileName + " cannot be decrypted, reason: " + e1.Message;
            }
            catch (Exception e2)
            {
                returnMessage = tag + ":" + fullFileName + " cannot be decrypted, reason: " + e2.Message;
            }

            Trace.WriteLine(returnMessage);
        }


Trace output

1:C:\temp\test-aspose-pdf\1_AES128_user_only_sample.pdf has been decrypted with password successfully

Exception thrown: ‘Aspose.Pdf.InvalidPasswordException’ in Aspose.PDF.dll
2:C:\temp\test-aspose-pdf\2_AES128_user_only_sample.pdf cannot be decrypted, reason: Invalid password

3:C:\temp\test-aspose-pdf\3_AES128_user_owner_sample.pdf has been decrypted with password successfully

4:C:\temp\test-aspose-pdf\4_AES128_user_owner_sample.pdf has been decrypted with password successfully

5:C:\temp\test-aspose-pdf\5_AES256_user_only_sample.pdf has been decrypted with password successfully

Exception thrown: ‘Aspose.Pdf.InvalidPasswordException’ in Aspose.PDF.dll
6:C:\temp\test-aspose-pdf\6_AES256_user_only_sample.pdf cannot be decrypted, reason: Invalid password

7:C:\temp\test-aspose-pdf\7_AES256_user_owner_sample.pdf has been decrypted with password successfully

Exception thrown: ‘Aspose.Pdf.InvalidPasswordException’ in Aspose.PDF.dll
8:C:\temp\test-aspose-pdf\8_AES256_user_owner_sample.pdf cannot be decrypted, reason: Invalid password

However, the results are not what I expected, particularly for case 3, 7 and 8.
The decrypt API was able to decrypt using just user password for 128 and 256-bit,
but unable to decrypt using owner permissions password for 256-bit!

Please advise.
Thank you!

test-aspose-pdf.zip (45.7 KB)

@dhsalvinit

Thank you for contacting support.

We have worked with the data shared by you and have been able to reproduce the issue in our environment. A ticket with ID PDFNET-46007 has been logged in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.