~ubuntu-branches/ubuntu/intrepid/ruby1.8/intrepid-updates

« back to all changes in this revision

Viewing changes to sample/openssl/cipher.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env ruby
 
2
require 'openssl'
 
3
 
 
4
text = "abcdefghijklmnopqrstuvwxyz"
 
5
pass = "secret password"
 
6
salt = "8 octets"        # or nil
 
7
alg = "DES-EDE3-CBC"
 
8
#alg = "AES-128-CBC"
 
9
 
 
10
puts "--Setup--"
 
11
puts %(clear text:    "#{text}")
 
12
puts %(password:      "#{pass}")
 
13
puts %(salt:          "#{salt}")
 
14
puts %(cipher alg:    "#{alg}")
 
15
puts
 
16
 
 
17
puts "--Encrypting--"
 
18
des = OpenSSL::Cipher::Cipher.new(alg)
 
19
des.pkcs5_keyivgen(pass, salt)
 
20
des.encrypt
 
21
cipher =  des.update(text)
 
22
cipher << des.final
 
23
puts %(encrypted text: #{cipher.inspect})
 
24
puts
 
25
 
 
26
puts "--Decrypting--"
 
27
des = OpenSSL::Cipher::Cipher.new(alg)
 
28
des.pkcs5_keyivgen(pass, salt)
 
29
des.decrypt
 
30
out =  des.update(cipher)
 
31
out << des.final
 
32
puts %(decrypted text: "#{out}")
 
33
puts