Encryption and decryption operations when logging on to thinksns using php-java

Source: Internet
Author: User
The api indicates that the account must be encrypted by des and the password must be encrypted by des and md5. However, authentication fails when I use several des encryption methods. I am using java. below is the php code I found from thinksns. I want to convert it to java. php really doesn't understand key $ key; return $ this;} functionencrypt ($ string) {$ ivArrayarray (0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF); $ ivnull; fore... phpjavades

The api indicates that the account must be encrypted by des and the password must be encrypted by des and md5. However, authentication fails when I use several des encryption methods.
I am using java. below is the php code I found from thinksns. I am eager to turn it into java. php really doesn't understand it.


   

class DES_MOBILE {
var $key = '12345678';

function  setKey($key){    $this->key = $key;    return $this;}function encrypt($string) {    $ivArray=array(0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF);    $iv=null;    foreach ($ivArray as $element)        $iv.=CHR($element);    $size = mcrypt_get_block_size ( MCRYPT_DES, MCRYPT_MODE_CBC );     $string = $this->pkcs5Pad ( $string, $size );      $data =  mcrypt_encrypt(MCRYPT_DES, $this->key, $string, MCRYPT_MODE_CBC, $iv);    $data = base64_encode($data);    return $data;}function decrypt($string) {    $ivArray=array(0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF);    $iv=null;    foreach ($ivArray as $element)        $iv.=CHR($element);    $string = base64_decode($string);    $result =  mcrypt_decrypt(MCRYPT_DES, $this->key, $string, MCRYPT_MODE_CBC, $iv);    $result = $this->pkcs5Unpad( $result );      return $result;} function pkcs5Pad($text, $blocksize)  {      $pad = $blocksize - (strlen ( $text ) % $blocksize);      return $text . str_repeat ( chr ( $pad ), $pad );  }  function pkcs5Unpad($text)  {      $pad = ord ( $text {strlen ( $text ) - 1} );      if ($pad > strlen ( $text ))          return false;      if (strspn ( $text, chr ( $pad ), strlen ( $text ) - $pad ) != $pad)          return false;      return substr ( $text, 0, - 1 * $pad );  }  

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.