数据格式
* @param args * 撞库---入参加密字段signs加密前格式 * * { * "mobileMask": "134123412**", * "city": "武汉", * "system": "qxh" * } * * 撞库---返回加密字段signs加密前格式 * { * "md5List": [ * "01f32b38b7b208a574c512a40d30cff0", * "01f32b38b7b208a574c512a40d30cff0" * ] * }
java版
import cn.hutool.crypto.SecureUtil; import cn.hutool.http.HttpUtil; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import lombok.Data; import lombok.experimental.Accessors; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.List; import java.util.Map; public class Demo { /** * 引入依赖 * <dependency> * <groupId>cn.hutool</groupId> * <artifactId>hutool-all</artifactId> * <version>5.6.5<</version> * </dependency> * * @param args * 撞库---入参加密字段signs加密前格式 * * { * "mobileMask": "134123412**", * "city": "武汉", * "system": "qxh" * } * * 撞库---返回加密字段signs加密前格式 * { * "md5List": [ * "01f32b38b7b208a574c512a40d30cff0", * "01f32b38b7b208a574c512a40d30cff0" * ] * } */ public static void main(String[] args) { //撞库----------------------------------------------------------------- String checkUrl = "撞库url"; String timestamp = String.valueOf(System.currentTimeMillis()); String key = String.format("%s%s", "MCXBIjANke", timestamp).substring(0, 16); CheckVO checkVO = new CheckVO(); checkVO.setMobileMask("134123412**") .setCity("武汉") .setSystem("qxh"); String signs = SecureUtil.aes(key.getBytes(StandardCharsets.UTF_8)).encryptHex(JSONUtil.toJsonStr(checkVO)); Map<String, Object> map = new HashMap<>(); map.put("timestamp", timestamp); map.put("signs", signs); String resultData = HttpUtil.createPost(checkUrl).contentType("application/json") .body(JSONUtil.toJsonPrettyStr(map)).timeout(5000).execute().body(); //请求完成---------------解析结果 JSONObject jsonObject = JSONUtil.parseObj(resultData); String result = jsonObject.getStr("result"); JSONObject data = jsonObject.getJSONObject("data"); String signsReturn = data.getStr("signs"); //-----------解密 String decryptStr = SecureUtil.aes(key.getBytes(StandardCharsets.UTF_8)).decryptStr(signsReturn); JSONObject md5Map = JSONUtil.parseObj(decryptStr); JSONArray md5Array = md5Map.getJSONArray("md5List"); List<String> md5List = md5Array.toList(String.class); System.out.println(JSONUtil.toJsonStr(md5List)); //撞库----------------------------------------------------------------- } @Data @Accessors(chain = true) public static class CheckVO { private String mobileMask; private String city; private String system; } }View Code
php版
代码在线运行网址 https://www.cainiaojc.com/tool/php/
<?php $key = 'MCXBIjANke172760'; // 生成一个随机的16字节密钥 $data = '{"md5List":[]}'; // 使用 PKCS5Padding $padding = 16 - (strlen($data) % 16); $dataPadded = $data . str_repeat(chr($padding), $padding); // 加密 $encrypted = openssl_encrypt($dataPadded, "AES-128-ECB", $key, OPENSSL_RAW_DATA, openssl_random_pseudo_bytes(16)); // 加密后的数据通常需要进行 base64 编码以便存储或传输 $encryptedBase64 = base64_encode($encrypted); $encryptedHex = bin2hex($encrypted); echo "加密后的数据(Base64): " . $encryptedHex . "\n"; // 解密 $decrypted = openssl_decrypt($encrypted, "AES-128-ECB", $key, OPENSSL_RAW_DATA, substr($encrypted, 0, 16)); // 移除填充 $pad = ord($decrypted[strlen($decrypted) - 1]); $decrypted = substr($decrypted, 0, -1 * $pad); echo "解密后的数据: " . $decrypted . "\n"; ?>View Code
标签:java,String,demo,撞库,加解密,hutool,signs,import,php From: https://www.cnblogs.com/qq376324789/p/18442756