-2

I'm trying to adapt the following function from C# to PHP and I can't get it to work. I've already searched other threads, but couldn't find the right answer to solve my problem.

public static string Decrypt(string EncryptedText)
{
    byte[] bytes = Encoding.ASCII.GetBytes("hello");
    byte[] buffer = Convert.FromBase64String(EncryptedText);
    byte[] rgbKey = new Rfc2898DeriveBytes("world", bytes).GetBytes(0x20);

    ICryptoTransform transform = new RijndaelManaged { Mode = CipherMode.CBC }.CreateDecryptor(rgbKey, bytes);
    MemoryStream stream = new MemoryStream(buffer);
    CryptoStream stream2 = new CryptoStream(stream, transform, CryptoStreamMode.Read);
    byte[] buffer4 = new byte[buffer.Length];

    int count = stream2.Read(buffer4, 0, buffer4.Length);
    stream.Close();
    stream2.Close();

    return Encoding.UTF8.GetString(buffer4, 0, count);
}

Any help appreciated. Thanks!

nurtext
  • 1
  • 3

1 Answers1

0

My PHP code so far:

<?php
$key = hash_pbkdf2('sha1', 'world', 'hello', 1000, 32);
$decrypted = mcrypt_decrypt(
            MCRYPT_RIJNDAEL_128,
            $key,
            'very long encrypted string',
            MCRYPT_MODE_CBC,
            'world');
?>
nurtext
  • 1
  • 3