I need to send an encrypted string to a client who is then using Java for decryption. The problem is that my encryption is no where near what it needs to be.
Here are the parameters they are using;
Algorithm: 3-DES
Mode: CBC
Padding: PKCS5
Key Hashing: MD5
IV: 00000000
Encoding: Base64
Here is my php code;
function pkcs5_pad ($text, $blocksize)
{
$pad = $blocksize - (strlen($text) % $blocksize);
return $text . str_repeat(chr($pad), $pad);
}
$string = "string to encrypt";
// pad the string
$size = mcrypt_get_block_size('tripledes', 'cbc');
$string = pkcs5_pad($string, $size);
// create iv
$iv = '00000000';
// hash the key
$my_key = md5("MYKEY");
// final encryption
$enc_string = mcrypt_encrypt(MCRYPT_3DES, $my_key, $string, MCRYPT_MODE_CBC, $iv);
//and finally Base64 encoding
$final_string = base64_encode($enc_string);
I read quite a bit about getting php to be compatible with Java on this and this seemed like the correct way to go?