Commit a2ed5c70 authored by 赵啸非's avatar 赵啸非

添加国密4加解密接口

parent f0fd6959
package com.mortals.xhx.common.utils;
import org.apache.commons.codec.binary.Hex;
import javax.crypto.Cipher;
import java.net.URLDecoder;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Base64;
public class RSAUtils {
// 私钥
private static final String PRIVATE_KEY = "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAJJuFUH/4m9H5hCCzxtd9BxpjWlG9gbejqiJpV0XJKaU1V7xDBJasswxPY7Zc15RoxWClPoKPwKrbWKm49dgBJebJq5xd4sLCSbboxRkKxpRiJHMZ4LJjYa5h9Ei9RyfoUzqGHqH4UrDy3m3IwPiP19cIBqoU50shyQf92ZpcGZhAgMBAAECgYEAiadU8pODoUs82x6tZbPALQmJN4PO+wwznfqv6sA74yGdKECAMazz0oMjtGt1SiCCqFD2jcweCftvvELZg3mvNg1V0vRQRD1ZCA8HDp8DXm20d11K3+RX39tR4KgyyM3HsSEhkUDujMxKIpYjyiB5iEtV7Ja9bZ2fROszq+mUIqUCQQDQQf6vWRMLBqfnDcU77vuDGOhXbjkF2ytLxLW3fbKaW3GWvC3n93zPM+mcvWSXgkl448+jFjpMktm1Vn+w+YX3AkEAs/+bbRbod6AcVbLu8C5E44qDRoRpu+LF7Cphp8tlSAIRjm2yGP5acMWGRUtH9MF2QJYPF0PgDzdmUSVqWnCAZwJBALnSuRri4wAKn1SmT+ALfLZcSiyBODZGeppv2ijw6qWahH8YR+ncRaxoyMFHqPMbmM1akJIXqktbGREaLnPOIb8CQQCdJycJaL3Qa98xR4dr9cm5rF6PO96g5w6M8jfO6ztjUkMHymh7f99wpFRlvaN2Y06edyV315ARWPohEPy5N44zAkBlLuDHLm1TkTTAfdlL5r2OcdjpaJYloTdn05Mp3+J+w1zTX8k6Mz8lFZtLUcoMeTfQ9rm/+u2KwxS8NljtSZWH";
public static String decode(String encodeStr, String privateKey) {
String decodeStr = null;
try {
byte[] decodeHexStr = Hex.decodeHex(encodeStr.toCharArray());
privateKey = privateKey.replaceAll(" +", "+");
byte[] privateKeyByte = Base64.getDecoder().decode(privateKey);
PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(privateKeyByte);
KeyFactory RSAKeyFactory = KeyFactory.getInstance("RSA");
PrivateKey key = RSAKeyFactory.generatePrivate(privateKeySpec);
Cipher cipher = Cipher.getInstance(RSAKeyFactory.getAlgorithm());
cipher.init(2, key);
byte[] bytes = cipher.doFinal(decodeHexStr);
decodeStr = URLDecoder.decode(new String(bytes), "utf-8");
} catch (Exception e) {
System.out.println("RSAdecode error: " + e);
}
return decodeStr;
}
public static void main(String[] args) {
String content="130fddec666d6a60ca27ca64e36706d3ee52ee710795636db1fb15a564d2abef1aaa13ab86eaaf534dc4e5e39033f07206a69057519a9a85ecb987c8307dd2514fb6cebcb763c16630cd3941476bb02a96133333c3e8e3d7ebe2fdac0d478d5338d928a1048213b27de330e1c8cd6eea80543f9a12789ab078c4ce96008f242b";
System.out.println(RSAUtils.decode(content,PRIVATE_KEY));
}
}
......@@ -195,4 +195,28 @@ Content-Type: application/json
###字典获取
GET {{baseUrl}}/param/dict?first=SkinBase&second=imageResolution
\ No newline at end of file
GET {{baseUrl}}/param/dict?first=SkinBase&second=imageResolution
###国密4加密
POST {{baseUrl}}/api/encrypt
Content-Type: application/json
{
"algorithm": "SM4",
"content": "ererfeiisgod",
"key": "QZTiVtyFIUjMCVLs",
"password": "QZTiVtyFIUjMCVLs",
"url": "https://cdsmk.cdrsigc.com/engine/rest/99999800009"
}
###国密4解密
POST {{baseUrl}}/api/decrypt
Content-Type: application/json
{
"algorithm": "SM4",
"content": "tbP0GEuSqSboA8qHissswQ==",
"key": "QZTiVtyFIUjMCVLs",
"password": "QZTiVtyFIUjMCVLs"
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment