summaryrefslogtreecommitdiff
path: root/sample/openssl/cipher.rb
diff options
context:
space:
mode:
authornahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-09-04 10:31:29 +0000
committernahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-09-04 10:31:29 +0000
commit5f84c80fc580bdd64b0f2f67a92a840965148e40 (patch)
treeacc6999a9b0b08b1bd645d0eadb9553d7c034b32 /sample/openssl/cipher.rb
parent11d439a7bdd714a8b3a057be8a7a6afc01249f31 (diff)
* sample/openssl: added. Sample of standard distribution library should be
locate in sample/{module_name}/*. * ext/openssl/sample/*: removed. move to sample/openssl/*. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample/openssl/cipher.rb')
-rw-r--r--sample/openssl/cipher.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/sample/openssl/cipher.rb b/sample/openssl/cipher.rb
new file mode 100644
index 0000000000..844b6eea4e
--- /dev/null
+++ b/sample/openssl/cipher.rb
@@ -0,0 +1,29 @@
+#!/usr/bin/env ruby
+require 'openssl'
+
+text = "abcdefghijklmnopqrstuvwxyz"
+key = "key"
+alg = "DES-EDE3-CBC"
+#alg = "AES-128-CBC"
+
+puts "--Setup--"
+puts %(clear text: "#{text}")
+puts %(symmetric key: "#{key}")
+puts %(cipher alg: "#{alg}")
+puts
+
+puts "--Encrypting--"
+des = OpenSSL::Cipher::Cipher.new(alg)
+des.encrypt(key) #, "iv12345678")
+cipher = des.update(text)
+cipher << des.final
+puts %(encrypted text: #{cipher.inspect})
+puts
+
+puts "--Decrypting--"
+des = OpenSSL::Cipher::Cipher.new(alg)
+des.decrypt(key) #, "iv12345678")
+out = des.update(cipher)
+out << des.final
+puts %(decrypted text: "#{out}")
+puts