I trying to do some cryptography between ruby and php, I don’t get
it!!!
ruby code:
#!/usr/bin/env ruby
require ‘openssl’
text = “abcdefghijklmnopqrstuvwxyz”
key = “altakey”
alg = “AES-128-ECB”
puts %(clear text: “#{text}”)
puts %(symmetric key: “#{key}”)
puts %(cipher alg: “#{alg}”)
puts “–Encrypting–”
des = OpenSSL::Cipher::Cipher.new(alg)
des.encrypt(key)
cipher = des.update(text)
cipher << des.final
puts %(encrypted text: #{cipher.inspect})
puts
This is the result:
“\214\t\303n\320Lz\330\271\252\017\355\036\251|\237\212V\270hq\267X\204\261\3327t\345\353\324\364”
what is that? \214???\t\303n?
this is the php code:
<?php $crypt = '\214\t\303n\320Lz\330\271\252\017\355\036\251|\237\212V\270hq\267X\204\261\3327t\345\353\324\364'; $key = "altakey"; echo "crypted content from ruby: " .$crypt . "\n"; $result = mcrypt_decrypt ( MCRYPT_RIJNDAEL_128 , $key, $crypt, MCRYPT_MODE_ECB); echo "result: $result\n" ?>this is the result:
ãå�dg[0l?�gª�¤½C¶(Ayy2�zeõt
AÃ?e:vb¶Uu<²é%fiÂ
czÃÃ?¯
wtf???
by the way, this is a code to encrypt in php
<?php $text = "abcdefghijklmnopqrstuvwxyz"; $key = "altakey"; echo "decrypted content: $text\n"; echo "key: $key\n"; $result = mcrypt_encrypt ( MCRYPT_RIJNDAEL_128 , $key, $text, MCRYPT_MODE_ECB); echo "Encrypted text: " . bin2hex($result) . "\n"; ?>this is the result:
1fce1c90530b80a27b1af29364ba45759870f1a2341c380dcc48845335d9e575
how can I manage that hex data in ruby? any help on anything?