[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

ezcrypto

bob@bob.com

6/14/2007 3:05:00 PM

require 'ezcrypto'

key = EzCrypto::Key.new "1234567812345678", :algorithm=>"blowfish"
key.encrypt_file "en.dll", "crypt.dll"
key.decrypt_file "crypt.dll","en.dll"

encrypts the 4,382,208 bytes file into a 29,003 bytes file decrypting
this then obviously fails. This code works ok with small text files ok.

Oh please don't RTFM me cos the documentation is up to the usual Ruby
standard ;)
Ruby, so much power so little documentation.

Thanks for any help,
Bob

--
Posted via http://www.ruby-....

4 Answers

Jim flip

6/14/2007 8:06:00 PM

0

Hmmm I get the same problem, seems like it dies if the file is greater
than 256 bytes, dunno if that means much.

I don't think what Jason said is very relevant, and their does seem to
be an issue. The documentation is typically bad and I personally do
find that very annoying, people can find the time to write blogs and
publish this stuff but can't spend 10 minutes writing some simple sample
code. I have posted on the relevant ruby forge forum but I would not
expect to get a message anytime soon.

Fixing the bug might well be very time consuming as it is a wrapper
around Openssl, and we don't know if the issue is with that or ezcrypto.

Move on then I guess, but to what? The crypto gem works okay if you only
need to crypt small files but is very slow on big files, not practical
for our plans.

Look at OpenSSL gem directly I guess, but you will have a hard time
finding useful documentation for that either me thinks.

Anyone know how to crypt files with Blowfish using Openssl, to late at
night now for me to try that!

Jim.

--
Posted via http://www.ruby-....

Jim flip

6/15/2007 9:10:00 AM

0


here's some basic code that will encrypt a file with blowfish and CBC,
note it doesn't do the last block of the file that is less than 8 bytes.

require 'openssl'

key = "1234567812345678"
alg = "BF-CBC"
iv = "00000000"

bf = OpenSSL::Cipher::Cipher.new(alg)
bf.encrypt
bf.key = key
bf.iv = iv

File.open("openssl.dat",'wb') do |enc|

File.open("test.txt","rb") do |f|
size = File.size("test.txt")
blocks = size / 8

for i in 1..blocks
r = f.read(8)
cipher = bf.update(r)
enc << cipher
end
end

enc << bf.final
end

You can also speed it up by doing more efficient read from file, anyhoo
Openssl file encryption with Blowfish seems ok, I can get back on with
the work I'm meant to be doing now :)

Jim.

--
Posted via http://www.ruby-....

Jim flip

6/15/2007 9:12:00 AM

0

Also note that it does not write the IV at the beginning of the file,
would be something you need to add if you require that.

Oh and I was able to decrypt this using my C version of Blowfish not
from Openssl.

Jim.

--
Posted via http://www.ruby-....

Jim flip

6/18/2007 10:41:00 AM

0

File.open("test.enc",'wb') do |enc|

File.open("test.txt","rb") do |f|
size = File.size("test.txt")
blocks = size / 8

for i in 1..blocks
r = f.read(8)
cipher = bf.update(r)
enc << cipher
end

if size%8 >0
r = f.read((size%8))
cipher = bf.update(r)
enc << cipher
end
end

enc << bf.final
end

That does the trick, I think the bf.final should sort out the padding.
In fact I wouldn't be surprised if you didn't have to feed update 8
bytes at a time, but not tested...NOTE: this is just test code that
works, and isn't efficient.

Jim.

--
Posted via http://www.ruby-....