mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00

* ext/openssl/ossl_cipher.c (ossl_s_ciphers): new method OpenSSL::Cipher.ciphers. it returns all the cipher names. * ext/openssl/lib/openssl/cipher.rb: - add constants AES128, AES192, AES256. [ruby-dev:28610] - reimplement without eval() * ext/openssl/lib/openssl/digest.rb: reimplement without eval(). * test/openssl/test_cipher.rb, test_digest: fix about reimplemented features. * sample/openssl/cipher.rb: rewrite all. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@10339 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
33 lines
715 B
Ruby
33 lines
715 B
Ruby
#!/usr/bin/env ruby
|
|
require 'openssl'
|
|
|
|
text = "abcdefghijklmnopqrstuvwxyz"
|
|
pass = "secret password"
|
|
salt = "8 octets" # or nil
|
|
alg = "DES-EDE3-CBC"
|
|
#alg = "AES-128-CBC"
|
|
|
|
puts "--Setup--"
|
|
puts %(clear text: "#{text}")
|
|
puts %(password: "#{pass}")
|
|
puts %(salt: "#{salt}")
|
|
puts %(cipher alg: "#{alg}")
|
|
puts
|
|
|
|
puts "--Encrypting--"
|
|
des = OpenSSL::Cipher::Cipher.new(alg)
|
|
des.pkcs5_keyivgen(pass, salt)
|
|
des.encrypt
|
|
cipher = des.update(text)
|
|
cipher << des.final
|
|
puts %(encrypted text: #{cipher.inspect})
|
|
puts
|
|
|
|
puts "--Decrypting--"
|
|
des = OpenSSL::Cipher::Cipher.new(alg)
|
|
des.pkcs5_keyivgen(pass, salt)
|
|
des.decrypt
|
|
out = des.update(cipher)
|
|
out << des.final
|
|
puts %(decrypted text: "#{out}")
|
|
puts
|