我想知道如何在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这是我正在尝试的实际代码:
<?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 />");
$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 />");?>
发布于 2011-02-16 01:51:32
您可以使用mcrypt库来使用Rijndael-128加密算法。
$td = mcrypt_module_open('Rijndael-128', '', 'ECB');有关示例,请参阅http://ca3.php.net/mcrypt_module_open
https://stackoverflow.com/questions/5006766
复制相似问题