Hello all,
Hoping someone can help me out here. I''ve burned almost a week trying
to figure out how to decrypt
an image file that has been encrypted using Blowfish CBC.
I found some code on the net and have modified as follows:
require ''openssl''
require ''digest/sha1''
ivArr = [0x0D,
0x0E,
0x0A,
0x0D,
0x0F,
0x0A,
0x0C,
0x0E
]
iv = ivArr.pack("cccccccc")
bf = OpenSSL::Cipher::Cipher.new("BF-CBC")
key = Digest::SHA1.hexdigest("fOyBtMaN4u2T")
bf.decrypt
bf.key = key
bf.iv = iv
File.open("C:\\mapcrypt\\MAP.TIFF",''wb'') do
|enc|
File.open("C:\\mapcrypt\\EncryptedMAP.TIFF","rb") do
|f|
size = File.size("C:\\mapcrypt\\EncryptedMAP.TIFF")
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
However, this returns the error:
OpenSSL::CipherError: wrong final block length
from (irb):89:in `final''
from (irb):89
from (irb):72:in `open''
from (irb):72
I''ve also tried using the Blowfish library:
require ''crypt/blowfish''
blowfish = Crypt::Blowfish.new("fOyBtMaN4u2T")
blowfish.decrypt_file(''C:\\mapcrypt\\11225035.00X'',
''MAP.TIFF'')
But this returns the error:
NoMethodError: undefined method `%'' for true:TrueClass
from c:/ruby/lib/ruby/gems/1.8/gems/crypt-1.1.4/./crypt/
blowfish.rb:84:in `decrypt_pair''
from c:/ruby/lib/ruby/gems/1.8/gems/crypt-1.1.4/./crypt/
blowfish.rb:82:in `downto''
from c:/ruby/lib/ruby/gems/1.8/gems/crypt-1.1.4/./crypt/
blowfish.rb:82:in `decrypt_pair''
from c:/ruby/lib/ruby/gems/1.8/gems/crypt-1.1.4/./crypt/
blowfish.rb:104:in `decrypt_block''
from c:/ruby/lib/ruby/gems/1.8/gems/crypt-1.1.4/./crypt/cbc.rb:
62:in `decrypt_stream''
from c:/ruby/lib/ruby/gems/1.8/gems/crypt-1.1.4/./crypt/cbc.rb:
99:in `decrypt_file''
from (irb):93
I''m using ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
Thanks in advance for your help,
Allen
akt-UM300TINZ1VWk0Htik3J/w@public.gmane.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---