php - AES-Rijndael 128 encryption in Java -
i have snippet in php encrypts plain string using aes 128 encryption.
i have problem use in java not have experience on cryptography.
take @ php snippet here:
function encrypt_text($decrypted) { $thepasskey = "my_key_some_gibberish_key"; # add pkcs7 padding. $str = $decrypted; // gets block size of specified cipher // mode: cbc // cipher name: rijndael_128 $block = mcrypt_get_block_size(mcrypt_rijndael_128, mcrypt_mode_cbc); echo "encryption: ".mcrypt_rijndael_128."<br/>"; echo "mcrypt mode: ".mcrypt_mode_cbc."<br/>"; echo "block: " . $block."<br/>"; if (($pad = $block - (strlen($str) % $block)) < $block){ $str .= str_repeat(chr($pad), $pad); } // returns size of iv belonging specific cipher/mode combination $iv_size = mcrypt_get_iv_size(mcrypt_rijndael_128, mcrypt_mode_cbc); $iv = ''; for($i = 0; $i < $iv_size; $i++){ $iv .= "\0"; } // mcrypt_encrypt: encrypts plaintext given parameters // base6_encode: encodes data mime base64 return base64_encode(mcrypt_encrypt(mcrypt_rijndael_128, $thepasskey, $str, mcrypt_mode_cbc, $iv)); }
from above snippet, i've managed requirement needs encrypt string are:
encryption mode: rijndael-128
mcrypt mode: cbc
block: 16
so, how do java? i'm implementing in android app, if helps.
Comments
Post a Comment