note 51223 deleted from ref.mcrypt by danbrown

From: Date: Mon, 13 Dec 2010 16:26:18 +0000
Subject: note 51223 deleted from ref.mcrypt by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-174864@lists.php.net to get a copy of this message
Note Submitter: IRLCoder ---- Just a followup note about mcrypt<-->java interop (have a php app encrypting a string and a java app decrypting it - and vice-versa!) it seems that mcrypt pads with nulls (0x00) instead of spaces so to allow the interop to work properly (where both java and php/mcrypt encode strings to the same value) - I padded the PHP strings with spaces first before encrypting and did the same on the Java side - thus the padding was the same on each side and the interop is complete. Here's sample PHP for padding: $dlen = strlen($data); $pad = fmod($dlen, 16); if ($pad > 0) { $i = (int)$pad; while ($i > 0) { $data.=" "; $i--; } } and here's the Java padding: public static String PadString(String in) { int slen = (in.length() % 16); int i = (16 - slen); if ((i > 0) && (i < 16)){ StringBuffer buf = new StringBuffer(in.length() + i); buf.insert(0, in); for (i = (16 - slen); i > 0; i--) { buf.append(" "); } return buf.toString(); } else { return in; } } With trimming on each side for decryption ... all works well.

« previous php.notes (#174864) next »