Class Aes_mcrypt {private $hex _iv = ' 00000000000000000000000000000000 '; # converted JAVA byte code in to hex and place D it here function __construct ($key) {$this->key = hash (' sha256 ', $key, true); } function Encrypt ($str) {$td = Mcrypt_module_open (mcrypt_rijndael_128, ', MCRYPT_MODE_CBC, '); Mcrypt_generic_init ($TD, $this->key, $this->hextostr ($this->hex_iv)); $block = Mcrypt_get_block_size (mcrypt_rijndael_128, MCRYPT_MODE_CBC); $block = Mcrypt_enc_get_block_size ($TD); $str = $this->addpadding ($str, $block); $encrypted = Mcrypt_generic ($TD, $STR); Mcrypt_generic_deinit ($TD); Mcrypt_module_close ($TD); Return Base64_encode ($encrypted); } function Decrypt ($code) {$td = Mcrypt_module_open (mcrypt_rijndael_128, ', MCRYPT_MODE_CBC, '); Mcrypt_generic_init ($TD, $this->key, $this->hextostr ($this->hex_iv)); $str = Mdecrypt_generic ($TD, Base64_decode ($code)); Mcrypt_generic_deinit ($TD); Mcrypt_module_close ($TD); return $this->strippadding ($STR); }/* for PKCS7 padding */Private Function addpadding ($string, $blocksize = +) {$len = strlen ($str ing); $pad = $blocksize-($len% $blocksize); $string. = Str_repeat (Chr ($pad), $pad); return $string; } Private Function Strippadding ($string) {$slast = Ord (substr ($string,-1)); $SLASTC = Chr ($slast); $pcheck = substr ($string,-$slast); if (Preg_match ("/$SLASTC {"). $slast. "}/", $string)) {$string = substr ($string, 0, strlen ($string)-$slast); return $string; } else {return false; }} Public Function Hextostr ($hex) {$string = '; for ($i =0; $i < strlen ($hex)-1; $i +=2) {$string. = Chr (Hexdec ($hex [$i]. $hex [$i +1]); } return $string; }}