Hello developers

I need a favor to know where i am getting wrong. I am doing encryption using TripleDes using Bouncy castle. I use php on server side to decrypt it. I wonder if is there any padding problem. I can not figure it out. The followig is my code for both the sides. I would appreciate your effort.

Text-"This is a test Text"

Output-+óÚÛÈ?ga test Text


public String performEncrypt(String key, String plainText)

BlockCipher engine = new DESedeEngine();
BufferedBlockCipher cipher = new PaddedBlockCipher(new CBCBlockCipher(engine));

byte[] keyBytes = key.getBytes();
byte[] input = plainText.getBytes();

cipher.init(true, new KeyParameter(keyBytes));

byte[] cipherText = new byte[cipher.getOutputSize(input.length)];

int outputLen = cipher.processBytes(input, 0, input.length, cipherText, 0);
cipher.doFinal(cipherText, outputLen);
catch (CryptoException ce)

return new String(Base64.encode(cipherText)).trim();



$encrypted = $_GET['id'];
$iv = mcrypt_create_iv (mcrypt_get_block_size (MCRYPT_TripleDES, MCRYPT_MODE_CBC), MCRYPT_DEV_RANDOM);

// Decrypting
function decrypt($string, $key) {
$dec = "";
$string = trim(base64_decode($string));
global $iv;
$dec = mcrypt_cbc (MCRYPT_TripleDES, $key, $string, MCRYPT_DECRYPT, $iv);
return $dec;

$decrypted = decrypt($encrypted, $key);

echo "Decrypted is ".$decrypted ;

Kind Regards