Dave123 Posted June 2, 2010 Share Posted June 2, 2010 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. Key-XiTo74dOO09N48YeUmuvbL0E Text "This is a test Text" Output +óÚÛÈ?ga test Text //J2me 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); try { cipher.doFinal(cipherText, outputLen); } catch (CryptoException ce) { System.err.println(ce); System.exit(1); } return new String(Base64.encode(cipherText)).trim(); }//decryptText //PHP <?php $key="XiTo74dOO09N48YeUmuvbL0E"; $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 Link to comment https://forums.phpfreaks.com/topic/203694-encryption-using-triple-des/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.