Encrypting text in ruby

Available Ciphers

Can use any of these ciphers
  • blowfish
  • cast
  • des
  • idea
  • rc2
  • rc4
  • rc5
  • dsa
  • dh
  • rsa

Example Code

This is How you encrypt things in ruby

To encrypt
   require 'openssl'

   cipher = OpenSSL::Cipher::Cipher.new( "des-ecb" )
   cipher.encrypt
   cipher.key = key_to_use
   cipher.iv = iv_to_use

   output = cipher.update( data_to_encrypt )
   output << cipher.update( more_data_to_encrypt )
   output << cipher.final
Or, to decrypt:
   cipher = OpenSSL::Cipher::Cipher.new( "des-ecb" )
   cipher.decrypt
   cipher.key = key_to_use
   cipher.iv = iv_to_use

   output = cipher.update( data_to_dencrypt )
   output << cipher.update( more_data_to_dencrypt )
   output << cipher.final

This topic: Main > RubyLangEncryption
Topic revision: 24 May 2006, CharlesDupont
 
This site is powered by FoswikiCopyright © 2013-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Vanderbilt Biostatistics Wiki? Send feedback