开发者

Rijndael-128 ECB on PHP

I would like to know how can I do this on PHP:

Public Function DesencriptarRijndael(ByVal texto As String, ByVal key As String, ByRef Respuesta As Integer, ByRef Mensaje As String) As String
    Dim algoritmo As New System.Security.Cryptography.RijndaelManaged()
    Try
        algoritmo.Key = Convert.FromBase64String(key)
        algoritmo.Mode = CipherMode.ECB

        Dim decryptor As ICryptoTransform = algoritmo.CreateDecryptor()
        Dim data As Byte() = Convert.FromBase64String(texto)
        Dim dataDecrypted As Byte() = decryptor.TransformFinalBlock(data, 0, data.Length)
        Return Encoding.Unicode.GetString(dataDecrypted)
    Catch ex As Exception
        Respuesta = 7
        Mensaje = "Se esperaba la cadena de texto en formato encriptado"
        Return Nothing
    End Try
End Function

This is the actual code with the one I'm trying:

<?php
function fn_cargarTexto()
{
    $filename = "Encriptado.txt";

    $textoCargado = "";

    $file = fopen($filename, "r");

    while(!feof($file))
    {
        $textoCargado = $textoCargado . fgets($file, 4096);
    } // Fin del while.

    fclose($file);

    return $textoCargado;
} // Fin de la función fn_cargarTexto.

$llave = "XtoDU1JaWgZWg18Qf1g96A==";
echo("llave" . " = " . $llave . "<br />");

$llave64 = base64_decode($llave);
echo("llave64" . " = " . $llave64 . "<br />开发者_如何学Go;");

$textoCargado = fn_cargarTexto();
echo("textoCargado" . " = " . $textoCargado . "<br />");

$textoCargado64 = base64_decode(textoCargado);
echo("textoCargado64" . " = " . $textoCargado64 . "<br />");

// 128 192 256

$algoritmoCifrado = MCRYPT_RIJNDAEL_128;
echo("algoritmoCifrado" . " = " . $algoritmoCifrado . "<br />");

$modoCifrado = MCRYPT_MODE_ECB;
echo("modoCifrado" . " = " . $modoCifrado . "<br />");

$tamano = mcrypt_get_iv_size($algoritmoCifrado, $modoCifrado);
echo("tamano" . " = " . $tamano . "<br />");

$iv = mcrypt_create_iv($tamano, MCRYPT_DEV_RANDOM);
echo("iv" . " = " . $iv . "<br />");

$resultado = mcrypt_decrypt($algoritmoCifrado, $llave, $textoCargado, $modoCifrado, $iv);
echo("resultado" . " = " . $resultado . "<br />");

?>


You can use the mcrypt library to use the Rijndael-128 encryption algorithm.

$td = mcrypt_module_open('Rijndael-128', '', 'ECB');

See http://ca3.php.net/mcrypt_module_open for examples

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜