Posted By

chrisaiv on 10/21/07


Tagged

ruby encyption decryption EzCrypto


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

webstic
4rp70x1n


Encrypting / Decrypting Passwords using EzCrypto


 / Published in: Ruby
 

First things First you need to install this ruby gem user$ sudo gem install ezcrypto

  1. ############################
  2. #1. Encryption
  3. ############################
  4. #A. Import the Libraries
  5. require 'rubygems'
  6. require 'ezcrypto'
  7.  
  8. #B. Create AES 128-bit Key
  9. # => 1. Make a strong alpha-numeric password longer then 8-bytes
  10. # => 2. Create a Salt or two-form hash
  11. @key = EzCrypto::Key.with_password("alph@_num3r1c", "salted hash")
  12.  
  13. #C. Encrypt the Data
  14. @encrypted = @key.encrypt "$up3r_p@$$w0rd"
  15.  
  16. puts "This is your encrypted data \n" + @encrypted
  17.  
  18. ############################
  19. #2. Decryption
  20. ############################
  21. #A. Establish the Key like you did in Step A above
  22.  
  23. #B. Decrypt the Original Message
  24. @decrypted = @key.decrypt @encrypted
  25.  
  26. puts "This is the decrypted original data \n" + @decrypted

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: chetan on November 1, 2007

hello friend

i used ezcrpto for password generation in my rails app , and its not get stored in mysql db giving charset error

here is the error

ActiveRecord::StatementInvalid (Mysql::Error: Illegal mix of collations (latin1swedishci,IMPLICIT) and (utf8generalci,COERCIBLE) for operation '=': SELECT * FROM users WHERE (users.status = 'active' AND users.password = '/s&µ^õÍZ&Ó£ÿà' AND users.email = '[email protected]') LIMIT 1):

thanks in advance reguard chetanM

You need to login to post a comment.