I need to decrypt a string encrypted with MS SQL ENCRYPTBYPASSPHRASE with PHP or MySQL.
I already tried using mcrypt in various ways which just returns strings like '���h� �¯��������|�niIW�q;ɵJ��i��� ��7�'. Also tried different block-modes like "ecb", "cbc", "cfb", "ofb", "nofb" or "stream".
I also tried using DES_DECRYPT in MySQL which just returns the same as the input.
The PHP function i tried:
public function Decrypt($data, $secret){
//Generate a key from a hash
$key = md5(utf8_encode($secret), true);
//Take first 8 bytes of $key and append them to the end of $key.
$key .= substr($key, 0, 8);
$data = base64_decode($data);
$data = mcrypt_decrypt('tripledes', $key, $data, 'ecb');
$block = mcrypt_get_block_size('tripledes', 'ecb');
$len = strlen($data);
$pad = ord($data[$len-1]);
return substr($data, 0, strlen($data) - $pad);
}
The MySQL i tried:
SELECT DES_DECRYPT( 'string', 'key:mykey' ) AS decrypt
I hope you can help me find a solution to this problem.
Thanks in advance.