Files
epay/plugins/jdpay/inc/common/TDESUtil.php
T
opencode b7613ba082 部署仓库初始化:epay 部署配置、补丁与插件
- docker-compose.prod.yml:挂载 epay-ui.css/js/head.php 补丁到 staging(镜像升级不丢)
- docker/nginx.conf:补丁静态资源 no-cache,改版立即生效
- patches/:
  - test.php 修复 paytype JSON 对象导致测试支付页空白
  - epay-ui.css 后台全屏/侧栏加宽/导航两列布局覆盖
  - epay-ui.js 去除页面容器宽度限制 + 侧栏当前菜单自动滚动
  - head.php 资源 ?v= 版本号强制回源
  - functions.php is_public_url 白名单等既有补丁
- plugins/ 支付插件源码
- .gitignore 排除 .env 等敏感与临时文件
2026-10-21 13:05:20 +08:00

60 lines
1.5 KiB
PHP

<?php
class TDESUtil {
/**
* 将元数据进行补位后进行3DES加密
* <p/>
* 补位后 byte[] = 描述有效数据长度(int)的byte[]+原始数据byte[]+补位byte[]
*
* @param
* sourceData 元数据字符串
* @return 返回3DES加密后的16进制表示的字符串
*/
public static function encrypt2HexStr($keys, $sourceData) {
$length = strlen($sourceData);
$result = '';
for($i = 0; $i < 4; $i ++) {
$shift = (4 - 1 - $i) * 8;
$result .= chr(($length >> $shift) & 0x000000FF);
}
$result .= $sourceData;
$add = 8 - ($length+4) % 8;
if($add>0){
for($i=0; $i<$add; $i++){
$result .= chr(0);
}
}
$desdata = self::encrypt( $result, $keys );
return bin2hex( $desdata );
}
/**
* 3DES 解密 进行了补位的16进制表示的字符串数据
*
* @return
*
*/
public static function decrypt4HexStr($keys, $data) {
$unDesResult = self::decrypt(hex2bin($data),$keys);
$length=0;
for($i = 0; $i < 4; $i ++) {
$shift = (4 - 1 - $i) * 8;
$length += (ord($unDesResult[$i]) & 0x000000FF) << $shift;
}
$result = substr($unDesResult, 4, $length);
return $result;
}
// 加密算法
public static function encrypt($input, $key) {
return openssl_encrypt($input, 'des-ede3', $key, OPENSSL_NO_PADDING, "");
}
// 解密算法
public static function decrypt($encrypted, $key) {
return openssl_decrypt($encrypted, 'des-ede3', $key, OPENSSL_NO_PADDING, "");
}
}