cancel
Showing results for 
Search instead for 
Did you mean: 

Mailing PDF Attachment with Password Protected

Former Member
0 Kudos

Hi All,

I have requirement, where i need to send the mail Attachment with password protected. I am using Smartform in my Program to create PDF File.. could any one help me in making this attachments password protected.

Thanks

Shashikanth

Accepted Solutions (0)

Answers (4)

Answers (4)

ansonabraham
Participant
0 Kudos

Hi shashikanth

Hope this link will solve your problem.

http://scn.sap.com/docs/DOC-29209

Regards,

Anson

Former Member
0 Kudos

Hello all,

if you need a pure ABAP based solution please check:

http://www.pdfencryption.de

Regards,

Steffen Gruber

Former Member
0 Kudos

Hi Gruber,

When I run my report for PDF Encryption the the follwing message come

Access via 'NULL' object reference not possible.

593

594 * set the PDF and the encryption

595   CREATE OBJECT o_pdf.

596   o_pdf->set_pdf_file( result ).

597

598   pass = 'TEST'.

599

600   upass = pass.

601 *  CONCATENATE 'O_' pass INTO opass.

602   opass = 'ATEST'.

603   CREATE OBJECT o_encrypt_aes

604     EXPORTING

605       keylength = 128.

606 *  o_encrypt ?= o_encrypt_aes.

607

608 * set the user permissions for the PDF file

>>>   o_encrypt->set_permission_ex( print_allowed = 'X'

610                                 modify_allowed = ' '

611                                 copy_allowed = 'X'

612                                 add_annotations_allowed = ' '

613                                 fill_fields_allowed = ' '

614                                 copy_accessibility_allowed = 'X'

615                                 assemble_allowed = ' '

616                                 print_highres_allowed = 'X' ).

617

618 * set the user and the owner password for the PDF

619   o_encrypt->set_passwords( user_password = upass owner_password =

620 * generate the passwords

621   o_encrypt->generate_passwords( o_pdf ).

( as per your API_Reference.pdf I create 2 class CL_PDF & CL_PDF_ENCRYPTION and also copy CL_PDF_ENCRYPTION to CL_PDF_ENCRYPTION_AES )

Please you guide me with screen shot for Class & Method.

With Warm Regards

Manob Chatterjee

Former Member
0 Kudos

Hello Manob,

just remove the comment at line 606. This will cast the object reference of o_encrypt_aes and assign it to o_encrypt. After this assignment o_encrypt is a valid object reference and so the o_encrypt->set_permission_ex doesn't terminate with NULL object reference.

Cheers,

Steffen

Former Member
0 Kudos

Hello Steffen,

When I uncomment at line 606 then the following message show.....

A cast between two incompatible references (to the types

"CL_PDF_ENCRYPTION" and "CL_PDF_ENCRYPTION_AES") makes no sense. This

kind of cast will always produce a runtime error .

Please advice me.

Regards

Manob Chatterjee

Former Member
0 Kudos

Hello Manob,

the API is a reference of the PDF Encryption Library. All the functions and classes are implemented there. The two classes /GRUBE/CL_PDF_ENCRYPTION and /GRUBE/CL_PDF_ENCRYPTION_AES are part of a hierarchy and can be casted into the base class  /GRUBE/CL_PDF_ENCRYPTION. It seems that you have tried to implement the classes by yourself and so you have also implement the rest of the functionality which is provided by the  PDF Encryption Library.

Cheers,

Steffen

Former Member
0 Kudos

Hello Steffen,

Please you guide me with screen shot for 2 Class with Method.

Regards

Manob

Former Member
0 Kudos

Hello Manob,

that's not so simple. To encrypt PDF in SAP you have to do the following steps inside the class:

- disassemble the existing PDF (from spool or ADS)

- implement AES and RC4 and some other algorithms (e.g. compression/decompressin)

- use the ISO specification 32000_2008 to do the encryption

- assemble the final PDF

There is no standard functionality in the SAP ABAP stack, which covers any of these areas.

This is basically the functionality of the PDF Encryption Library (see: www.pdfencryption.de).

Cheers,

Steffen

Former Member
0 Kudos

Hi Gruber,

How did you write this code(pdfencryption.de)?

Appreciate if you could give us some clues.

Thank You.

Former Member
0 Kudos

Hello Poorna Soysa,

yes I wrote this code. What kind of clues do you need?

Cheers

Former Member
0 Kudos

Hi Gruber,

Thank you for replying.

Is it native ABAP code or did you use 3rd party tool to write this code? Actually  I'm stuck on PDF encrypt part.:

Cheers

Former Member
0 Kudos

Hi Poorna Soysa,

it is pure ABAP OO code. Everything is implemented in ABAP and can simply be installed by importing an SAP transport request. Apart from an SAP ABAP application server no additional software is required.

Cheers

Steffen Gruber 

Former Member
0 Kudos

Hi Gruber,


Thanks for replying again..


I am new 2 ABAP. To encrypt PDF in SAP no standard method. How do you write ABAP code for PDF encryption?


Cheers

Former Member
0 Kudos

Hi Poorna Soysa,

The SAP ABAP stack has no standard functionality to encrypt PDFs (at least as far as I know). There is some part of the functionality implemented in the ADS (Java Stack). However I was never successful to control the owner and user password and the PDF security settings from the ABAP stack or in any other manageable way.

To implement PDF encryption in ABAP just buy and download the PDF specification from http://www.iso.org/iso/catalogue_detail.htm?csnumber=51502 ( ISO 32000-1:2008 ) and implement all the required functions in ABAP.

Cheers,

Steffen

Former Member
0 Kudos

hi steffen,

In this lync they used some custom classes . can you please share the code also ....

Former Member
0 Kudos

Hello Kishna,

which classes do you refer to? The whole package consists of about 150 classes (around 50000 lines of code) and these are an ABAP OO implementation of ISO 32000-1:2008 and the Adobe Addon for AES 256.

Cheers,

Steffen

Former Member
0 Kudos

hi steffen,

thanks for your reply ,

I need the code for these 3 classes.

     data: o_pdf type ref to /grube/cl_pdf.
ata: o_encrypt_aes type ref to /grube/cl_pdf_encryption_aes.
data: o_encrypt type ref to /grube/cl_pdf_encryption.


Regards,

Krishna.

OttoGold
Active Contributor
0 Kudos

Hello, if you want your PDF to be password protected then:

1) you cannot print smartform because if there would be something like PDF protection, it would definitely NOT be applicable on smartform print (PDF is the "dumb" conversion, this is not a PDF in the sense of Adobe Forms).

2) you cannot password protect the PDF anyway, this question has been answered many times under NetWeaver - Interactive forms by Adobe. You can check these threads to confirm this:

Password protect PDF file:

Hope this solves (proves not possible) your question.

Regards, Otto

ChrisPaine
Active Contributor
0 Kudos

Well....

Hi Otto - I must disagree - but possibly agree too.

There is no standard way in SAP (that I know of) of password protecting a PDF.

However, I have successfully password protected and encrypted a read only PDF from SAP. We do this as part of a solution to email employees their payslips.

It requires a little bit of work - especially the encryption bit - but it is possible.

But not as standard.

I'm really not sure if this also applies to offline forms - am tempted to try - would be great as part of a recruitment/hire process to be able to mail the form to a potential employee and separately communicate the password - ensures that any data sent to and forth is secure.

Have you ever tried something like that? Or is there some new tooling available these days?

Cheers,

Chris

Former Member
0 Kudos

Hi Chris,

We have a req to email employees their payslips in PDF formats with password protection. Could you please share your solution for encryption.

Appreciate your help.

Thanks,

Sangeetha K

former_member196555
Participant
0 Kudos

Hello Chris,

Can you share the logic that you used for encrypting the PDF document?

It would be a great learning for all of us.

Thank you.

Regards,

Harshad.

ChrisPaine
Active Contributor
0 Kudos

Hi Guys,

sorry I can't share the code - the company I work for makes money by selling it to people - I can't just grab it and run. I'm sure they'd be happy to sell it to you

That said - they don't hold a copyright on the idea! - If you look closely, Adobe have released the PDF specifications that tell you exactly how a PDF document is formatted.

If you look at the version of PDF that SAP code (as standard) produces - it is a very old version for which the specs are easily found. (from memory it's the 1.4 version that is output).

In the PDF specs it details how the encryption is done. (This is the hard part). You need to build an rc4 (or arc4) encryption routine in SAP - helpfully SAP have md5 hash routines built in - then encrypt the part of the document that need to be encrypted...

This link -[http://www.cs.cmu.edu/dst/Adobe/Gallery/anon21jul01-pdf-encryption.txt|http://www.cs.cmu.edu/dst/Adobe/Gallery/anon21jul01-pdf-encryption.txt] explains a little how you need to break up the doc, digest, etc and do the encryption.

If I had time and my own SAP HR system, I'd do a "clean room" implementation and post it up on SCN. But at the moment, time is highly prized and I've got other priorities.

That said - a good programmer should be able to take the above link, some further web searches and build their own implementation in a few days. Just remember to set both owner and user passwords (and generate a random owner password each time) to ensure that document cannot be easily ripped open.

It's also worth noting that the method I described here allows for 40bit encryption - which can be [brute forced relatively easily.|http://www.net-security.org/secworld.php?id=5561]. If you can code for longer key, then I suggest that you do (just don't export your code outside the USA Depends on to what lengths you want to go to protect the data.

Good luck.

Cheers,

Chris

Former Member
0 Kudos

Hi Chris,

Thanks for your post.

I followed the same steps as per you and could get pdf protected password popup.Can you please guide me  how to write RC4 in ABAP? I had done lot of research in web ,but was still confused in building RC4 algorithm.

Looking forward hearing from you.

Regards,

kris

Former Member
0 Kudos

Hi Chris,

Waiting for your reply.

I had made progress in RC4 algorithm,i could encrypt the plain text with key stream generated from RC4 algorithm using BIT-XOR operator and passed  values to /U and /O respectively as per PDF specs.

But still document is not getting decrypted. I feel like i am missing something in RC4 encryption.

Can you please help me in building RC4 routine in SAP.

Looking forward hearing from you.

Regards,

kris

Former Member
0 Kudos

Hi Kris,

It will be really appriciated if you will explain how you have manged to generate the PDF with password protected.

Thanks in advance.

Regards

Unmesh

Former Member
0 Kudos

Hi Kris,

Kindly share information if any, it will be appreciate.

Former Member
0 Kudos

This message was moderated.

former_member194416
Contributor
0 Kudos

Same required from me some time ago. But I could not find a solution.

Result I have reached that time was it is not possible to do using standard functionality in SAP and you may only do it after implementing some adobe solutions (which means additional software, hardware and development costs).

I mean adding password for sure. E-mailing is quite simple and you can find many examples here.

Edited by: Gungor Ozcelebi on Feb 3, 2010 10:28 AM