From: Nathan Taylor-Hoover Date: 2007-06-16T00:50:55+09:00 Subject: Re: ezcrypto ------=_Part_61121_19423794.1181922656330 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline It seems like you would need to add padding to this method to encrypt the whole file, but then how would your decryption process know how to remove the padding unless it is implemented in the same program? Must be a better way to do this using openssl/ezcrypto. I have Applied Cryptography sitting on my desk right now which should provide a clue on how this is usually handled. Unfortunately I also have "required" work to do today. :P Hope to keep this thread alive and work it to a resolution soon. - Nathan On 6/15/07, Jim flip wrote: > > > 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-forum.com/. > > ------=_Part_61121_19423794.1181922656330--