Here is PHP code I lifed out of a project that I've now abandoned. I'll find and post the Android side of things later. The basics are that I used the Rijndael-128+ECB encryption combined with Base-64 encoding to transmit information back and forth between the application and the web server. The catch, in this whole thing, is that on the Android side of things, you probably will need to do some manual padding at the end of your encrypted string in order to get things to work properly. Like I said, I'll post the Android side of things later.
I had intended to change the encryption key with every new version of my application, so be aware of that when you see $VERSION in my code. This isn't a complete example, just the encryption, decryption functions I had written. Raymond define('AES_V1_KEY','D0QgiY8JYvx8qzKx0iaN8kwEJgwpEqAJ'); function encryptString($RAWDATA,$VERSION = 1) { $key = null; switch($VERSION) { case 1: $key = AES_V1_KEY; break; } // encrypt string $td = mcrypt_module_open('rijndael-128','','ecb',''); $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND); mcrypt_generic_init($td,$key,$iv); $encrypted_string = mcrypt_generic($td, strlen($RAWDATA) . '|' . $RAWDATA); mcrypt_generic_deinit($td); mcrypt_module_close($td); // base-64 encode return base64_encode($encrypted_string); } function decryptString($ENCRYPTEDDATA,$VERSION = 1) { $key = null; switch($VERSION) { case 1: $key = AES_V1_KEY; break; } // base-64 decode $encrypted_string = base64_decode($ENCRYPTEDDATA); // decrypt string $td = mcrypt_module_open('rijndael-128','','ecb',''); $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND); mcrypt_generic_init($td,$key,$iv); $returned_string = mdecrypt_generic($td,$encrypted_string); unset($encrypted_string); list($length,$original_string) = explode('|',$returned_string,2); unset($returned_string); $original_string = substr($original_string,0,$length); mcrypt_generic_deinit($td); mcrypt_module_close($td); return $original_string; } jax wrote: > What would I use to: Encrypt a string in PHP and Decrypt that string > from Android? What methods are supported by both and which is the > most secure? > > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en