Re: Mimic AES_ENCRYPT and AES_DECRYPT functions in Ruby
- From: Felipe Coury <felipe.coury@xxxxxxxxx>
- Date: Tue, 24 Mar 2009 01:35:25 -0500
Just as a FYI, it works!!!
I forgot about the remains... Take a look at the final incarnation:
def mysql_key(key)
# The algorithm just creates a 16 byte buffer set to all zero,
final_key = "\0" * 16
# Number of string "blocks"
blocks, remain = key.length.divmod(16)
blocks.times do |i|
# For each block
key_block = key[i*16, 16]
# Runs bitwise XOR for each char on string
# and the same char on the block
16.times do |j|
final_key[j] ^= key_block[j]
end
end
if remain
remain.times do |i|
final_key[i] ^= key[(blocks * 16) + i]
end
end
final_key
end
And:
=> "dp&!{\021?pK?G!8[r."mkey = mysql_key(key)
User Load (2.9ms) SELECT * FROM `users` WHERE (`users`.`id` = 1)decrypt(mkey, User.find(1).password)
=> "password"
Just BEATIFUL!
Thanks a lot everyone!
--
Posted via http://www.ruby-forum.com/.
.
- Follow-Ups:
- Re: Mimic AES_ENCRYPT and AES_DECRYPT functions in Ruby
- From: Rob Biedenharn
- Re: Mimic AES_ENCRYPT and AES_DECRYPT functions in Ruby
- References:
- Mimic AES_ENCRYPT and AES_DECRYPT functions in Ruby
- From: Felipe Coury
- Re: Mimic AES_ENCRYPT and AES_DECRYPT functions in Ruby
- From: gcristelli
- Re: Mimic AES_ENCRYPT and AES_DECRYPT functions in Ruby
- From: Felipe Coury
- Re: Mimic AES_ENCRYPT and AES_DECRYPT functions in Ruby
- From: Felipe Coury
- Mimic AES_ENCRYPT and AES_DECRYPT functions in Ruby
- Prev by Date: Re: Mimic AES_ENCRYPT and AES_DECRYPT functions in Ruby
- Next by Date: [ANN] amalgalite 0.8.0 Released
- Previous by thread: Re: Mimic AES_ENCRYPT and AES_DECRYPT functions in Ruby
- Next by thread: Re: Mimic AES_ENCRYPT and AES_DECRYPT functions in Ruby
- Index(es):
Relevant Pages
|