T
Terry
After extensive searching I found only two examples of using openssl
ciphers; both on this list. (The "OpenSSL for Ruby" home page is, IMHO,
nearly worthless as a source of info.) The lack of available documentation
for Ruby and related projects is very frustrating; even ruby-doc.org wasn't
much help. But, I'm still here
One of the two examples I found works, the other does not (using Ruby
v1.8.0):
~~~~~ script start ~~~~~
require 'openssl'
myText = 'myTestString'
myKey = 'myPassword'
cipher = OpenSSL::Cipher::Cipher.new("DES")
cipher.encrypt( myKey )
result = cipher.update( myText )
result << cipher.final
puts "Encrypted \"#{myText}\" with \"#{myKey}\" to:\n\"#{result}\"\n"
cipher.decrypt( myKey )
result2 = cipher.update( result )
result2 << cipher.final
puts "Decrypted \"#{result}\" with \"#{myKey}\" to:\n\"#{result2}\"\n\n"
~~~~~ script end ~~~~~
produces:
~~~~~
Encrypted "myTestString" with "myPassword" to:
"ä{
1ÿ¯¿É8e[ú¯"
Decrypted "ä{
1ÿ¯¿É8e[ú¯" with "myPassword" to:
"myTestString"
~~~~~
while:
~~~~~ script start ~~~~~
require 'openssl'
myText = 'myTestString'
myKey = 'myPassword'
cipher = OpenSSL::Cipher::Cipher.new("DES")
cipher.key = myKey
cipher.encrypt(myText)
result = cipher.final
puts "Encrypted \"#{myText}\" with \"#{myKey}\" to:\n\"#{result}\"\n"
cipher.decrypt( result )
result2 = cipher.final
puts "Decrypted \"#{result}\" with \"#{myKey}\" to:\n\"#{result2}\"\n\n"
~~~~~ script end ~~~~~
produces:
~~~~~
Encrypted "myTestString" with "myPassword" to:
"7kCvDäï"
../cryptest.rb:14:in `final': wrong final block length (OpenSSL::CipherError)
from ./cryptest.rb:14
~~~~~
The above leads me to two questions:
1) Could and would someone please tell me why one works and the other does
not? Or at least point me to a reference doc so that I can figure it out
for myself?
2) Could and would someone please tell me what ciphers, other than DES, are
available with the "OpenSSL for Ruby" project? Or at least point me to a
reference doc? [The ChangeLog says all openssl ciphers have been added,
and according to the openssl-0.9.7a README, Blowfish should be available,
but attempting to initialize 'cipher' with #.new("Blowfish") produced
"Unsupported cipher algorithm (Blowfish)"; trying #.new("BLOWFISH")
produces "Unsupported cipher algorithm (BLOWFISH)"; and, oh look at that
"blowfish" works ... uhhh ... sort of ...]
3) Using Blowfish, the second script is still problematic changing its
error to:
~~~~~
../cryptest.rb:7:in `key=': key length too short: (OpenSSL::CipherError)
from ./cryptest.rb:7
~~~~~
This brings me back to question #1.
TIA,
Terry
ciphers; both on this list. (The "OpenSSL for Ruby" home page is, IMHO,
nearly worthless as a source of info.) The lack of available documentation
for Ruby and related projects is very frustrating; even ruby-doc.org wasn't
much help. But, I'm still here
One of the two examples I found works, the other does not (using Ruby
v1.8.0):
~~~~~ script start ~~~~~
require 'openssl'
myText = 'myTestString'
myKey = 'myPassword'
cipher = OpenSSL::Cipher::Cipher.new("DES")
cipher.encrypt( myKey )
result = cipher.update( myText )
result << cipher.final
puts "Encrypted \"#{myText}\" with \"#{myKey}\" to:\n\"#{result}\"\n"
cipher.decrypt( myKey )
result2 = cipher.update( result )
result2 << cipher.final
puts "Decrypted \"#{result}\" with \"#{myKey}\" to:\n\"#{result2}\"\n\n"
~~~~~ script end ~~~~~
produces:
~~~~~
Encrypted "myTestString" with "myPassword" to:
"ä{
1ÿ¯¿É8e[ú¯"
Decrypted "ä{
1ÿ¯¿É8e[ú¯" with "myPassword" to:
"myTestString"
~~~~~
while:
~~~~~ script start ~~~~~
require 'openssl'
myText = 'myTestString'
myKey = 'myPassword'
cipher = OpenSSL::Cipher::Cipher.new("DES")
cipher.key = myKey
cipher.encrypt(myText)
result = cipher.final
puts "Encrypted \"#{myText}\" with \"#{myKey}\" to:\n\"#{result}\"\n"
cipher.decrypt( result )
result2 = cipher.final
puts "Decrypted \"#{result}\" with \"#{myKey}\" to:\n\"#{result2}\"\n\n"
~~~~~ script end ~~~~~
produces:
~~~~~
Encrypted "myTestString" with "myPassword" to:
"7kCvDäï"
../cryptest.rb:14:in `final': wrong final block length (OpenSSL::CipherError)
from ./cryptest.rb:14
~~~~~
The above leads me to two questions:
1) Could and would someone please tell me why one works and the other does
not? Or at least point me to a reference doc so that I can figure it out
for myself?
2) Could and would someone please tell me what ciphers, other than DES, are
available with the "OpenSSL for Ruby" project? Or at least point me to a
reference doc? [The ChangeLog says all openssl ciphers have been added,
and according to the openssl-0.9.7a README, Blowfish should be available,
but attempting to initialize 'cipher' with #.new("Blowfish") produced
"Unsupported cipher algorithm (Blowfish)"; trying #.new("BLOWFISH")
produces "Unsupported cipher algorithm (BLOWFISH)"; and, oh look at that
"blowfish" works ... uhhh ... sort of ...]
3) Using Blowfish, the second script is still problematic changing its
error to:
~~~~~
../cryptest.rb:7:in `key=': key length too short: (OpenSSL::CipherError)
from ./cryptest.rb:7
~~~~~
This brings me back to question #1.
TIA,
Terry