Php-java encryption and decryption operations when logging on to Thinksns

Source: Internet
Author: User
Keywords PHP Java des
Phpjavades

API said in the login time account needs des encryption, the password needs des and MD5 encryption, but I used several DES encryption is the authentication failed.
I'm using Java, here is the PHP code I found from the Thinksns, ask the good people to turn into Java, PHP really do not understand


  
    

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); }

}

  • Related Article

    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.