Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/05/2013, 09:44
ivantj
 
Fecha de Ingreso: marzo-2012
Mensajes: 26
Antigüedad: 12 años, 1 mes
Puntos: 0
Comparar encriptado de ASP(Rijndael) en php

Que tal, espero me puedan ayudar con este problema que tengo y no se como solucionarlo, estuve buscando una forma en la web de como encryptar un password en php para compararlo con el mismo password pero encriptado desde ASP usando Rijndael.

He visto en algunas paginas algo parecido pero no me da, intento encriptar en php usando la funcion PBKDF1, pero al encriptar me marca un error:

Cita:
The IV parameter must be as long as the blocksize
,

el password que estoy queriendo comparar viene ya encriptado desde ASP usando la libreria
Cita:
using System.Security.Cryptography
.

y necesito encriptar la misma palabra en php para que al estar encriptadas las 2 las pueda comparar, en teoria siempre deben de dar el mismo resultado al encriptarse pero no me funcion :(

esta vendria siendo la parte en ASP para el encriptado:
Cita:
// Encrypt a string into a string using a password

// Uses Encrypt(byte[], byte[], byte[])

public string Encrypt(string clearText, string Password)
{

// First we need to turn the input string into a byte array.

byte[] clearBytes = System.Text.Encoding.Unicode.GetBytes(clearText);



// Then, we need to turn the password into Key and IV

// We are using salt to make it harder to guess our key using a dictionary attack -

// trying to guess a password by enumerating all possible words.

PasswordDeriveBytes pdb = new PasswordDeriveBytes(Password,

new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });



// Now get the key/IV and do the encryption using the function that accepts byte arrays.

// Using PasswordDeriveBytes object we are first getting 32 bytes for the Key

// (the default Rijndael key length is 256bit = 32bytes) and then 16 bytes for the IV.

// IV should always be the block size, which is by default 16 bytes (128 bit) for Rijndael.

// If you are using DES/TripleDES/RC2 the block size is 8 bytes and so should be the IV size.

// You can also read KeySize/BlockSize properties off the algorithm to find out the sizes.

byte[] encryptedData = Encrypt(clearBytes, pdb.GetBytes(32), pdb.GetBytes(16));



// Now we need to turn the resulting byte array into a string.

// A common mistake would be to use an Encoding class for that. It does not work

// because not all byte values can be represented by characters.

// We are going to be using Base64 encoding that is designed exactly for what we are

// trying to do.

return Convert.ToBase64String(encryptedData);

}
y la funcion que ejecuto en php es esta:

Código PHP:
    function Encrypt($pass$salt)
    {
        
$derived PBKDF1($pass$salt10048);
        
$key bin2hex(substr($derived032));
        
$iv bin2hex(substr($derived3216));
        return 
mcrypt_encrypt(MCRYPT_RIJNDAEL_128$key$passMCRYPT_MODE_CBC$iv);
    }
    function 
PBKDF1($pass$salt$count$dklen)
    {
        
$t $pass.$salt;
        
$t sha1($ttrue);
        for(
$i=2$i <= $count$i++)
        {
            
$t md5($ttrue);
        }
        
//$t = substr($t,0,$dklen-1);
        
$t substr($t,0,$dklen-1);
        return 
$t;
    } 
sus parametros son estos:

Código PHP:
Encrypt($key$Word
y me marca el siguiente error:
Cita:
Warning: mcrypt_encrypt() [function.mcrypt-encrypt]: The IV parameter must be as long as the blocksize
no se si alguien pudiera ayudarme, ya intente de todo un poco y nada :(