pluginaweek / encrypted_strings

Provides dead-simple string encryption/decryption syntax

This URL has Read+Write access

obrie (author)
Sun Jun 29 15:09:56 -0700 2008
commit  59b267bc3ccd867ceb36bce89c514c4195db086f
tree    51e4fc825571145273b3c337658cd6509ac29021
parent  7f77f42cf8ab091ffb90c39032b28994b97cf719
README.rdoc

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 greatly improves upon this syntax and adds straightforward support for encrypting values using SHA-1, Symmetric, and Asymmetric modes.

Usage

SHA Encryption

  >> password = "shhhh"
  => "shhhh"
  >> crypted_password = password.encrypt
  => "66c85d26dadde7e1db27e15a0776c921e27143bd"
  >> crypted_password.class
  => String
  >> crypted_password.encryptor
  => #<PluginAWeek::EncryptedStrings::ShaEncryptor:0x2b9238889460 @salt="salt">
  >> crypted_password == "shhhh"
  => true
  >> crypted_password.decrypt
  NotImplementedError: Decryption is not supported using a(n) PluginAWeek::EncryptedStrings::ShaEncryptor
          from ./script/../config/../config/../vendor/plugins/encrypted_strings/lib/encrypted_strings/encryptor.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 an encryptor instance which is used for future encryption and decryption of the string. The default encryptor uses SHA-1 encryption. For encryption modes 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, :key => "my_key")
  => "jDACXI5hMPI=\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