Note that there are some explanatory texts on larger screens.

plurals
  1. PODES Encryption in PHP and C#
    text
    copied!<p>I'm trying to achive the same DES encription that I've in an C# code but in PHP.</p> <p>The C# code looks like the following:</p> <pre><code>public static string EncriptarCadena(string strEncriptar) { DESCryptoServiceProvider provider; MemoryStream stream; CryptoStream stream2; string str2; string str = "29393651"; byte[] buffer2 = new byte[] { 0x45, 50, 0xa5, 0x18, 0x67, 0x58, 0xac, 0xba }; byte[] bytes = new byte[0]; try { bytes = Encoding.UTF8.GetBytes(str.Substring(0, 8)); provider = new DESCryptoServiceProvider(); byte[] buffer = Encoding.UTF8.GetBytes(strEncriptar); stream = new MemoryStream(); stream2 = new CryptoStream(stream, provider.CreateEncryptor(bytes, buffer2), CryptoStreamMode.Write); stream2.Write(buffer, 0, buffer.Length); stream2.FlushFinalBlock(); str2 = Convert.ToBase64String(stream.ToArray()); } catch (Exception) { str2 = ""; } finally { provider = null; stream = null; stream2 = null; } return str2; } </code></pre> <p>And the code that I've done till now in PHP is the following:</p> <pre><code>function encrypt($string) { //Key $key = "29393651"; $ivArray=array( 0x45, 50, 0xa5, 0x18, 0x67, 0x58, 0xac, 0xba ); $iv=null; foreach ($ivArray as $element) $iv.=CHR($element); echo "Key: $key IV: $iv&lt;br&gt;"; $encrypted_string = mcrypt_encrypt(MCRYPT_DES, $key, $string, MCRYPT_MODE_CBC, $iv); return base64_encode($encrypted_string); } </code></pre> <p>But I can't find where is the problem, as they don't give the same result for the same input.</p> <p>Any help will be very welcome :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload