diff options
Diffstat (limited to 'examples/ossl_cipher.rb')
-rwxr-xr-x | examples/ossl_cipher.rb | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/examples/ossl_cipher.rb b/examples/ossl_cipher.rb index 806daa8..e198c46 100755 --- a/examples/ossl_cipher.rb +++ b/examples/ossl_cipher.rb @@ -2,14 +2,26 @@ require 'openssl' include OpenSSL -include Cipher - -p des = DES.new('EDE3', 'CBC') #Des3 CBC mode -p "ENCRYPT" -p des.encrypt("key")#, "iv12345678") -p cipher = des.update("abcdefghijklmnopqrstuvwxyz") -p cipher += des.cipher -p "DECRYPT" -p des.decrypt("key") #, "iv12345678") -p des.update(cipher) + des.cipher + +text = "abcdefghijklmnopqrstuvwxyz" +key = "key" +alg = "DES-EDE3-CBC" +#alg = "AES-128-CBC" + +puts "ClearText = \"#{text}\"" +puts "SymmetricKey = \"#{key}\"" +puts "CipherAlg = \"#{alg}\"" + +des = Cipher::Cipher.new(alg) +puts "--Encrypting with key--" +des.encrypt("key")#, "iv12345678") +cipher = des.update(text) +cipher += des.final +puts "EncryptedText = #{cipher.inspect}" +puts "--Decrypting with key--" +des.decrypt(key) #, "iv12345678") +out = des.update(cipher) + des.final +puts "DecryptedText = \"#{out}\"" + +puts "DONE." |