Tuesday, December 2, 2008

URLEncrypt rolled out as plugin on Github

In my last post I talked about encrypting RESTful urls when we have to expose primary key in the URL. The plugin is generic and exposes handy methods.

Repository:
http://github.com/toamitkumar/url_encrypt/tree/master

Installation:
.scirpt/plugin install git://github.com/toamitkumar/url_encrypt.git

Usage:
Add the following line to your environment.rb file

UrlEncrypt.encryptors("abcdefghijklmnop", "mnbkjhkhkhkhkhkjhkjh")
#so that KEY and IV for Cipher encryption are different

OR

UrlEncrypt.encryptors("abcdefghijklmnop")
# so that KEY and IV for Cipher encryption are same

OR

NOTHING

Inside your model add the line:

class Book < ActiveRecord::Base
  column :id, :integer
column :title, :string

encrypted :with => :title
end

You have handy methods:
Book.find_by_encrypted_title('encrypted string')

Book.find_by_encrypted_title('encrypted string',
:conditions => ["any other condition can go here"])

Next step: To roll out the plugin as JRuby.

No comments: