# IText PDF Won't Permit Encryption?

**URL:** <https://www.ruby-forum.com/t/itext-pdf-wont-permit-encryption/143052>\
**Category:** Rails\
**Created:** [July 14, 2008, 8:50pm UTC](https://www.ruby-forum.com/t/itext-pdf-wont-permit-encryption/143052 "2008-07-14T20:50:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ror\_arch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ror\_arch](https://www.ruby-forum.com/u/ror_arch)\
**Post date:** [July 14, 2008, 8:50pm UTC](https://www.ruby-forum.com/t/itext-pdf-wont-permit-encryption/143052/1 "2008-07-14T20:50:53Z")

</div>

I am attempting to encrypt the file that is generated by Itext:

def download  
str = Rjb::import(“java.lang.String”);  
pw = Rjb::import(“com.lowagie.text.pdf.PdfWriter”)  
d = Rjb::import(“com.lowagie.text.Document”)  
ba = Rjb::import(“java.io.ByteArrayOutputStream”)  
b = ba.new()  
p = Rjb::import(“com.lowagie.text.Paragraph”)  
document = d.new()  
s = str.new(“user”)  
pwd = s.getBytes()  
writer = pw.getInstance(document, b)  
writer.setEncryption(pwd, pwd,2052,1);  
document.open()  
document.add(p.new(“Hello!!!”))  
document.close()  
bytes = b.toByteArray()  
send\_data(bytes, {:filename =\> “Letters For Printing.pdf”, :type =\>  
“application/pdf”})  
end

Every time I call the above method I get the error :

NoClassDefFoundError in LettersController#download

org/bouncycastle/asn1/ASN1OctetString

RAILS\_ROOT: C:/ruby/letter4sure  
Application Trace | Framework Trace | Full Trace

app/controllers/letters\_controller.rb:184:in `method_missing' app/controllers/letters_controller.rb:184:in`download’  
-e:2:in `load’  
-e:2

c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/base.rb:1158:in  
`send' c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in`require’  
script/server:3  
-e:2:in `load’  
-e:2

Request

Parameters:

{“id”=\>“77”}

Show session dump

* * *

:expires\_at: 2008-07-14 15:01:23.454000 -04:00  
:csrf\_id: ac3da650bca5dc0064b04b6f2b9c6632  
:refer\_to:  
:user\_id: 1  
:return\_to: /letters/download/75  
flash: !map:ActionController::Flash::FlashHash {}

Response

Headers:

{“cookie”=\>[],  
“Cache-Control”=\>“no-cache”}

–

It works if I comment out the setEncryption method. When I attempt to  
encrypt in the java file and then send the pdf I get the same error. :

NoClassDefFoundError in LettersController#download

org/bouncycastle/asn1/ASN1OctetString

RAILS\_ROOT: C:/ruby/letter4sure  
Application Trace | Framework Trace | Full Trace

app/controllers/letters\_controller.rb:172:in `method_missing' app/controllers/letters_controller.rb:172:in`download’

–

What is going on here? I went to itext so I could send encrypted  
files…
