summaryrefslogtreecommitdiffstats
path: root/ext/openssl/sample/cipher.rb
diff options
context:
space:
mode:
authorgotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-23 16:12:24 +0000
committergotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-23 16:12:24 +0000
commit2b5c2408119eb7b4605b3bbe4b32d2275afdb867 (patch)
tree10591a106bc2f3eff53eff8e440f58495ff517c9 /ext/openssl/sample/cipher.rb
parentef3e52e3c1cd81d6a631b4f28f82b7f1be78f459 (diff)
downloadruby-2b5c2408119eb7b4605b3bbe4b32d2275afdb867.tar.gz
ruby-2b5c2408119eb7b4605b3bbe4b32d2275afdb867.tar.xz
ruby-2b5c2408119eb7b4605b3bbe4b32d2275afdb867.zip
* ext/openssl: imported.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@4128 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/openssl/sample/cipher.rb')
-rw-r--r--ext/openssl/sample/cipher.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/ext/openssl/sample/cipher.rb b/ext/openssl/sample/cipher.rb
new file mode 100644
index 000000000..844b6eea4
--- /dev/null
+++ b/ext/openssl/sample/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