时间:2021-07-01 10:21:17 帮助过:5人阅读
/** * 传输的关键数据加密 * @param keyData 需加密值 * @param timestamp 时间戳 * @param dataSecret 密钥 * @return String 加密数据 */ public static String encryptKeyData(String keyData, Long timestamp, String dataSecret) { DateFormat df = new SimpleDateFormat(Constants.DATE_TIME_FORMAT); df.setTimeZone(TimeZone.getTimeZone(Constants.DATE_TIMEZONE)); keyData = df.format(new Date(timestamp)) + "aop" + keyData; return desEncryptToBase64(keyData, dataSecret.getBytes()); }
function encrypt($input) { $size = mcrypt_get_block_size('des', 'ecb'); $input = $this->pkcs5_pad($input, $size); $key = $this->key; $td = mcrypt_module_open('des', '', 'ecb', ''); $iv = @mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND); @mcrypt_generic_init($td, $key, $iv); $data = mcrypt_generic($td, $input); mcrypt_generic_deinit($td); mcrypt_module_close($td); $data = base64_encode($data); return $data; } function pkcs5_pad ($text, $blocksize) { $pad = $blocksize - (strlen($text) % $blocksize); return $text . str_repeat(chr($pad), $pad); }