rain
2024-08-12 dbecdea3ad1768d1c7f8e88a2d3b64193c62352a
src/main/java/com/dji/sample/droneairport/utils/SM4Util.java
@@ -111,8 +111,35 @@
        byte[] key = "jsimjrby3wqb7dbq".getBytes(StandardCharsets.UTF_8); // 16字节密钥
        // 原始明文
        String plaintext = "{ \"deviceid\": \"1581F6QAD241500BDZ3J\", \"status\": 1 }";
        String plaintext = "{\n" +
                "    \"deviceid\": [\n" +
                "        \"1581F5BMD22CK0014H2U\",\n" +
                "        \"1581F6QAD241800B6V95\"\n" +
                "    ],\n" +
                "    \"taskid\": \"b6e89a1e-5e89-4c9b-aa26-00faa4d8f568\",\n" +
                "    \"tasklist\": [\n" +
                "        {\n" +
                "            \"bsm\": \"2028107171717717107171017\",\n" +
                "            \"xzqdm\": \"310000\",\n" +
                "            \"dkbh\": \"ndbg201102U0172710711\",\n" +
                "            \"dklx\": \"ndbg2024\",\n" +
                "            \"dkmc\": \"小桥头\",\n" +
                "            \"dkmj\": 20.5,\n" +
                "            \"dkfw\": \"MULTIPOLYGON(((115.86528871951153 28.625287925196325,115.86561708513025 28.625787612007546,115.86815834948467 28.624602640426623,115.86773004650362 28.62425999804172,115.86528871951153 28.625287925196325)))\",\n" +
                "            \"bz\": null\n" +
                "        },\n" +
                "        {\n" +
                "            \"bsm\": \"202810717171777\",\n" +
                "            \"xzqdm\": \"310000\",\n" +
                "            \"dkbh\": \"ndbg201102U011\",\n" +
                "            \"dklx\": \"ndbg2024q\",\n" +
                "            \"dkmc\": \"桥头\",\n" +
                "            \"dkmj\": 27.5,\n" +
                "            \"dkfw\": \"MULTIPOLYGON(((115.8537683547021 28.626198084066036,115.85362014017156 28.625905772075246,115.85325749115422 28.625530171307133,115.8532121556319 28.625552314192735,115.85285649743213 28.625719691357663,115.8526650611681 28.62581016383709,115.85251948537035 28.62587896210428,115.8524159923293 28.625927871721817,115.85236695899066 28.625953724319036,115.85242053528945 28.626032126827145,115.85243919323472 28.626059431385023,115.85258924149208 28.626287013655055,115.85275847878526 28.62654053983997,115.85281562628226 28.62662918289837,115.8537683547021 28.626198084066036)))\",\n" +
                "            \"bz\": null\n" +
                "        }\n" +
                "    ]\n" +
                "}\n";
        String secert =encrypt(key,plaintext.getBytes());
//        System.out.println(secert);
@@ -120,11 +147,11 @@
        byte[] ming= Base64.getDecoder().decode(secert);
        byte[] text=decrypt(key,ming);
//        System.out.println(new String(text, StandardCharsets.UTF_8));
//        System.out.println("封装"+encrypt("jsimjrby3wqb7dbq",plaintext));
        System.out.println(encrypt("jsimjrby3wqb7dbq",plaintext));
//        System.out.println("封装"+decrypt("jsimjrby3wqb7dbq","9LFnVDdqleTOFcBJT7TSxs788zPH8PicodLb5634SsixHrKNX+ZAgwODPZxvWFNQ"));
        String encryptedBase64 = encrypt(key, plaintext.getBytes(StandardCharsets.UTF_8));
//        System.out.println("Encrypted (Base64): " + encryptedBase64);
        System.out.println(generateSM4Key());
//        System.out.println(generateSM4Key());
        // 直接解密
        byte[] decoded = Base64.getDecoder().decode(encryptedBase64);
        byte[] decrypted = decrypt(key, decoded);