R
Rodrigo Dominguez
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";
?>
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";
?>