Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/06/2011, 12:41
alx_salazar
 
Fecha de Ingreso: septiembre-2008
Mensajes: 192
Antigüedad: 15 años, 7 meses
Puntos: 1
Encriptar y desencriptar

hola a todos tengo dificultades para utilizar una librería PHP para encriptar y una biblioteca de rubí on rails para descifrar o alguien tiene alguna otra mejor forma de realizarlo.
RUBI ON RAILS
Código Rubi on rails:
Ver original
  1. require 'openssl'
  2.     file_path_key = "data.bin1"
  3.    
  4.     file_path_key_ = "wrapped.bin1"
  5. private_key_file = "private.key";
  6.   wrapped = File.read(file_path_key_)
  7.   cipher_text = File.read(file_path_key)
  8.  
  9.   privkey = OpenSSL::PKey::RSA.new(File.read(private_key_file))
  10.  #p privkey
  11.   key = privkey.private_decrypt(wrapped)
  12. #p  privkey.private_decrypt(Base64.decode64(File.read(file_path_key_)))
  13.   #p key
  14.     cipher = OpenSSL::Cipher.new('rc4')
  15.   cipher.decrypt
  16.  
  17.  
  18.   cipher.key = key
  19.  
  20. p cipher.update(cipher_text)

Código PHP:
Ver original
  1. $pubkey = openssl_pkey_get_public(file_get_contents('public.key'));
  2.  
  3. $message = 'hello,world';
  4. $cipher_text = "hi";
  5.  
  6. $keys = NULL;
  7. openssl_seal($message, $cipher_text, $keys, array($pubkey));
  8. echo sizeof($keys);
  9. $file = fopen('wrapped.bin1', 'wb');
  10. fwrite($file, $keys[0]);
  11. fclose($file);
  12.  
  13. $file = fopen('data.bin1', 'wb');
  14. fwrite($file, $cipher_text);
  15. fclose($file);