当前位置:   article > 正文

携程接口加解密_java携程接口文档解密

java携程接口文档解密
  1. class CtripAesService
  2. {
  3. private $key = 'xxx';
  4. private $iv = 'xxx';
  5. public function aes128_cbc_encrypt($data) {
  6. $key = $this->key;
  7. $iv = $this->iv;
  8. if(16 !== strlen($key)) $key = hash('MD5', $key, true);
  9. if(16 !== strlen($iv)) $iv = hash('MD5', $iv, true);
  10. $padding = 16 - (strlen($data) % 16);
  11. $data .= str_repeat(chr($padding), $padding);
  12. return $this->encode_bytes(openssl_encrypt($data,'AES-128-CBC',$key,OPENSSL_RAW_DATA,$iv));
  13. }
  14. public function aes128_cbc_decrypt($data) {
  15. $key = $this->key;
  16. $iv = $this->iv;
  17. if(16 !== strlen($key)) $key = hash('MD5', $key, true);
  18. if(16 !== strlen($iv)) $iv = hash('MD5', $iv, true);
  19. $data=openssl_decrypt( $this->decode_bytes($data), "AES-128-CBC", $key, OPENSSL_RAW_DATA, $iv);
  20. return $data;
  21. }
  22. public function decode_bytes($text){
  23. $bytes=array();
  24. for($i=0;$i<strlen($text);$i+=2){
  25. $char=$text[$i];
  26. $bytes[$i/2]=chr((ord($char)-ord('a'))<<4);
  27. $char=$text[$i+1];
  28. $bytes[$i/2]=chr(ord($bytes[$i/2])+(ord($char)-ord('a')));
  29. }
  30. return join('',$bytes);
  31. }
  32. public function encode_bytes($text){
  33. $bytes=array();
  34. for($i=0;$i<strlen($text);$i++){
  35. $bytes[]=chr(((ord($text[$i])>>4)&15)+ord('a'));
  36. $bytes[]=chr((ord($text[$i]) & 15)+ord('a'));
  37. }
  38. return join('',$bytes);
  39. }
  40. }
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/874818
推荐阅读
相关标签
  

闽ICP备14008679号