public
Rubygem
Description: Provides dead-simple string encryption/decryption syntax
Homepage: http://www.pluginaweek.org
Clone URL: git://github.com/pluginaweek/encrypted_strings.git
obrie (author)
Tue Jun 09 20:31:48 -0700 2009
commit  e5eb95f3c3625e16b937d030a1dcfaaba81a0386
tree    98d551465563bccef4e3a3b0e00e6cc1769d8a5f
parent  9917fc524267b741540fb1b79d356101ad53d778
name age message
file .gitignore Fri Jul 04 15:49:24 -0700 2008 Ignore test/app_root/script [obrie]
file CHANGELOG.rdoc Sun Jan 11 16:06:09 -0800 2009 Tag 0.3.2 release [obrie]
file LICENSE Tue Apr 14 20:09:45 -0700 2009 Update license [obrie]
file README.rdoc Sun Dec 14 17:54:25 -0800 2008 Remove the PluginAWeek namespace [obrie]
file Rakefile Tue Jun 09 20:31:48 -0700 2009 Add gemspec [obrie]
file encrypted_strings.gemspec Tue Jun 09 20:31:48 -0700 2009 Add gemspec [obrie]
file init.rb Wed Oct 25 18:19:47 -0700 2006 Refactored determination of the encryption mode... [obrie]
directory lib/ Sun Jan 11 16:05:43 -0800 2009 Tweak docs [obrie]
directory test/ Mon Dec 29 21:20:37 -0800 2008 Use Array#pack/String#unpack instead of Base64 ... [obrie]

encrypted_strings

encrypted_strings provides dead-simple string encryption/decryption syntax.

Resources

API

Bugs

Development

Source

  • git://github.com/pluginaweek/encrypted_strings.git

Description

Encrypting and decrypting data is not exactly the most straightforward and DRY way. encrypted_strings improves the syntax and reduces the complexity, adding straightforward support for encrypting values using SHA-1, Symmetric, and Asymmetric ciphers.

Usage

SHA Encryption

  >> password = 'shhhh'
  => "shhhh"
  >> encrypted_password = password.encrypt
  => "66c85d26dadde7e1db27e15a0776c921e27143bd"
  >> encrypted_password.class
  => String
  >> encrypted_password.cipher
  => #<EncryptedStrings::ShaCipher:0x2b9238889460 @salt="salt">
  >> encrypted_password == 'shhhh'
  => true
  >> encrypted_password.decrypt
  NotImplementedError: Decryption is not supported using a(n) EncryptedStrings::ShaCipher
          from ./script/../config/../config/../vendor/plugins/encrypted_strings/lib/encrypted_strings/cipher.rb:13:in `decrypt'
          from ./script/../config/../config/../vendor/plugins/encrypted_strings/lib/encrypted_strings/extensions/string.rb:52:in `decrypt'
          from (irb):40

When encrypt is called, it creates a cipher instance which is used for future encryption and decryption of the string. The default cipher uses SHA-1 encryption. For ciphers that do not support decryption, equality with other strings is tested by encrypting the other string and checking whether the resulting encrypted value is the same.

Symmetric Encryption

  >> password = 'shhhh'
  => "shhhh"
  >> crypted_password = password.encrypt(:symmetric, :password => 'secret_key')
  => "qSg8vOo6QfU=\n"
  >> crypted_password.class
  => String
  >> crypted_password == 'shhhh'
  => true
  >> password = crypted_password.decrypt
  => "shhhh"

Asymmetric encryption

  >> password = 'shhhh'
  => "shhhh"
  >> crypted_password = password.encrypt(:asymmetric, :public_key_file => './public.key', :private_key_file => './private.key')
  => "NEwVzcikYUKfS8HTc9L9eg/dMxBCLZ/nFr7J1aQYjkl3I2MPUD0lmjr/saC6\nTJEPwOl60Ki24H8TUwnGtZy14A==\n"
  >> crypted_password.class
  => String
  >> crypted_password == 'shhhh'
  => true
  >> password = crypted_password.decrypt
  => "shhhh"

Dependencies

None.

References