1

I need to encrypt String & send to sever which is in php.

Below you will find encryption code and function to encrypt it.

define('SALT', 'whateveryouwant'); 

function encrypt($text) 
{ 
        return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, SALT,
$text, MCRYPT_MODE_ECB,
mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB),
MCRYPT_RAND)))); 
} 

function decrypt($text) 
{ 
        return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, SALT,
base64_decode($text), MCRYPT_MODE_ECB,
mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB),
MCRYPT_RAND))); 

} 

I tried out some classes in android but did not work at all. Anybody having idea about the functions or classes in android which support this functionality?

Thanks in Advance

1 Answer 1

2

Android has javax.crypto package for this purpose.

Take a look at an example code for encrypting a string. Also useful is code to list all available cyphers.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.