I'm here are all the methods for encryption

def mysql_encrypt(s, key)
    encrypt(s, mysql_key(key))
  end

  def mysql_decrypt(s, key)
    puts s
    decrypt(s, mysql_key(key))
  end

  protected
  def aes(m,k,t)
    (aes = OpenSSL::Cipher::AES128.new("ECB").send(m)).key = k
    aes.update(t) << aes.final
  end

  def encrypt(text, key)
    aes(:encrypt, key, text)
  end

  def decrypt(text, key)
    aes(:decrypt, key, text)
  end

  def mysql_key(key)
    key = key.encode("UTF-8")
    final_key = "\0" * 16
    key.length.times do |i|
      final_key[i%16] = (final_key[i%16].ord ^ key[i].ord).chr
    end
    final_key

  end


When is use the key set to "test key" and string to be encrypted set to 
"Some text for encryption". The returned encrypted string is: 
"\x9E\xB6g\xB7\xF0\xF8\x9F 
M\xC1\x82\xA0\xFC\xEF[hY\xEC]=\xE6U\xE8o\xFBN\xCD\x929\x9A\xF4\xB5"

But the encrypted string should be: 
"9EB667B7F0F89F204DC182A0FCEF5B6859EC5D3DE655E86FFB4ECD92399AF4B5" 
(generated from C# mysql_mimic and Mysql itself)

My encrypted string appears some hexadecimal values interlaced and I'm 
not sure why or how "decode" it properly to match the desire encryption 
results.

The above results were produced in ruby 1.9.1 (which is what we are 
using for this project)

Thanks





Rob Biedenharn wrote:
> 
> What final_key do you expect?  You need to post the full code and
> input along with the expected value (or what 1.8.6 gives?) in order to
> help.
> 
> -Rob

-- 
Posted via http://www.ruby-forum.com/.