SpringBoot-RSA加密

前言

最近由于工作业务的需要,需要对指定的字段信息进行非对称加解密;由于需要加密的内容过于庞大;自己执行程序会出现:Data must not be longer than 117 bytes 的异常错误;现在自己将自己的解决方法总结如下;

一、配置文件准备

spring:
  profiles:
    active: dev
---
spring:
  profiles: dev

salary:
  rsa-key: MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQCe8a/Aq4h9l1aKU8j6dP89qzU3pvcmezsP2grr3yHWPzLOakP0qczmEcKCXi2gRWDhHgoSwlNOZR70dTV0FNBvL1OcEfnDlR5CCD8zHmwnfDkPIA+7aeM6FT/lqhIiejClrkkuhtrRgjNBaf75r+OEmznRP5a37HLdYRsXdBg39jubRk3ULvQpeVfbE4sjwEvzQEyosXdDV0iS/EubFqUlmISe+QAtaXLykRGu+/PVhfqspY6jXC1LkAlbXGty2c5/ixpCL38m/Q9GeS4VGj0EHVFkD+9XmQ+376zOsKLuoNEKiQChB+fx6cHVQk0QP+0VbCrGnNn6Jz4L4V8uvFnudehxYxBZKiOsiFjv7ZNhPd/A7hm8mgqWDvVHof6BKvanSoHJ74Qsh4SvzdRYyG8qtwA/QWklxalaklowoajnKNR7i7sUEoXmP47QYkJN+TEDxrD4pNn8+fKgQjrk8YPuLhdBau9M+TIxx8zL391d3x5+rOHmSDeQBq4e9MEtxKmNGoIVPenPpsrRrN6CsY+UgQ9rdblTNnQySG0z7qdus4qDO6PbuCXAdEE1uGzxuWXNUZTj5nG/3yVSnxW8+xUzB44cHhnP+D50tqYdwwDTEs88dklHC8FuybqtZ33pZybRjdnLIgYyyPQBY8GMy9sdwEIkMVPEgxn0Y4Agy5T6VwIDAQABAoICAHuGj7WoWhJpLFui0/46MSfHSDuxKkEg4nzmUziPGCf+w8iB88BQuqpPQSC6erElWi56fw+nMMEre4w3D0zg5ECUwmD342lqGbLt39glm55wP5QOsctQdsTsQNWHgEKFPgt1UPC045iRnK4I5507YhHr5VpHFiZov7hnQHvQwQW0+wwo7lGqEB2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brOQeUjbxcawThNUqI+1h5+lvZoPjbxk8W57qF1QqM61nZyIatG

二、对配置文件中的rsa-key属性获取

@ConfigurationProperties("salary")
@Component
public class RsaConfig {

    private String rsaKey;

    public String getRsaKey() {
        return rsaKey;
    }

    public void setRsaKey(String rsaKey) {
        this.rsaKey = rsaKey;
    }
}

三、RSAUtil工具类的编写

import com.tencent.citybase.generated.bridge.utils.SpringContextUtils;
import com.tencent.citybase.generated.extend.config.RsaConfig;
import org.apache.commons.codec.binary.Base64;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import javax.crypto.Cipher;
import java.io.ByteArrayOutputStream;
import java.security.*;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description RAS加密工具类
 * @Author songwp
 * @Date 2022/8/8 20:34
 * @Version 1.0.0
 **/
public class RSAUtil {
  protected static Logger log = LoggerFactory.getLogger(RSAUtil.class);

  private static final String KEY_ALGORITHM = "RSA";
  //密钥长度
  private static final int KEY_SIZE = 4096;

  //最大加密长度
  private static final int MAX_ENCRYPT_BLOCK = KEY_SIZE / 8 -11;
  //最大解密长度
  private static final int MAX_DECRYPT_BLOCK = KEY_SIZE / 8;

  private static String getRsaKey() {
      return SpringContextUtils.getBean(RsaConfig.class).getRsaKey();
  }

  private static byte[] decryptBASE64(String src) {
      BASE64Decoder decoder = new BASE64Decoder();
      try {
          return decoder.decodeBuffer(src);
      } catch (Exception ex) {
          return null;
      }
  }

/**
 * 生成公私钥
 *
 * @param keySize 密钥长度
 */
public static Map<String, String> genKeyPair(int keySize) {
    Map<String, String> keyMap = new HashMap<>();
    try {
        //创建密钥对生成器
        KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
        kpg.initialize(keySize);
        //生成密钥对
        KeyPair keyPair = kpg.generateKeyPair();
        //公钥
        PublicKey publicKey = keyPair.getPublic();
        //私钥
        PrivateKey privateKey = keyPair.getPrivate();
        keyMap.put("publicKey", Base64.encodeBase64String(publicKey.getEncoded()));
        keyMap.put("privateKey", Base64.encodeBase64String(privateKey.getEncoded()));
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        log.error("生成公私钥信息失败:"+e.getMessage());
    }
    return keyMap;
}


/**
 * 该base64方法会自动换行
 * @param src
 * @return
 */
private static String encryptBASE64(byte[] src) {
    BASE64Encoder encoder = new BASE64Encoder();

    return encoder.encode(src);
}
/**
 * 公钥分段加密
 * @param data 源数据
 * @param publicKey 公钥(BASE64编码)
 * @param length 段长
 * @return
 * @throws Exception
 */
private static byte[] encryptByPublicKey(byte[] data, String publicKey,int length) {
    ByteArrayOutputStream out = null;
    byte[] encryptData = null;
    try {
        byte[] keyBytes = decryptBASE64(publicKey);
        X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes);
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        Key publicK = keyFactory.generatePublic(x509KeySpec);
        // 对数据加密
        Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
        cipher.init(Cipher.ENCRYPT_MODE, publicK);
        int inputLen = data.length;
        out = new ByteArrayOutputStream();
        int offSet = 0;
        byte[] cache;
        int i = 0;
        // 对数据分段加密
        while (inputLen - offSet > 0) {
            if (inputLen - offSet > length) {
                cache = cipher.doFinal(data, offSet, length);
            } else {
                cache = cipher.doFinal(data, offSet, inputLen - offSet);
            }
            out.write(cache, 0, cache.length);
            i++;
            offSet = i * length;
        }
        encryptData = out.toByteArray();
    } catch (Exception e) {
        e.printStackTrace();
        log.error("公钥分段加密失败:"+e.getMessage());
    } finally {
        try {
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return encryptData;
}

/** *//**
 * <P>
 * 私钥解密
 * </p>
 *
 * @param data 已加密数据
 * @param privateKey 私钥(BASE64编码)
 * @return
 * @throws Exception
 */
private static byte[] decryptByPrivateKey(byte[] data, String privateKey,int length){
    ByteArrayOutputStream out = null;
    byte[] decryptedData = null;
    try {
        byte[] keyBytes =  decryptBASE64(privateKey);
        PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes);
        KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
        Key privateK = keyFactory.generatePrivate(pkcs8KeySpec);
        Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
        cipher.init(Cipher.DECRYPT_MODE, privateK);
        int inputLen = data.length;
        out = new ByteArrayOutputStream();
        int offSet = 0;
        byte[] cache;
        int i = 0;
        // 对数据分段解密
        while (inputLen - offSet > 0) {
            if (inputLen - offSet > length) {
                cache = cipher.doFinal(data, offSet, length);
            } else {
                cache = cipher.doFinal(data, offSet, inputLen - offSet);
            }
            out.write(cache, 0, cache.length);
            i++;
            offSet = i * length;
        }
        decryptedData = out.toByteArray();
    } catch (Exception e) {
        e.printStackTrace();
        log.error("私钥解密失败:"+e.getMessage());
    } finally {
        try {
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return decryptedData;
}

/**
 * 加密
 * @param data
 * @param publicKey
 * @return
 */
public static String encryptByPublicKey(String data, String publicKey) {
    //log.info("公钥分段加密内容:"+new String(encryptByPublicKey(data.getBytes(), publicKey, MAX_ENCRYPT_BLOCK)).replaceAll("[+]", "@"));
    return encryptBASE64(encryptByPublicKey(data.getBytes(), publicKey, MAX_ENCRYPT_BLOCK)).replaceAll("[+]", "@");
}

/**
 * 解密
 * @param data
 * @return
 */
public static String decryptByPrivateKey(String data) {
    //log.info("私钥解密内容:"+new String(decryptByPrivateKey(decryptBASE64(data.replaceAll("@", "+")), getRsaKey(), MAX_DECRYPT_BLOCK)));
    return new String(decryptByPrivateKey(decryptBASE64(data.replaceAll("@", "+")), getRsaKey(), MAX_DECRYPT_BLOCK));
}
public static void main(String[] args) { 
    Map<String, String> keyMap = genKeyPair(KEY_SIZE); System.out.println("公钥======"+keyMap.get("publicKey")); 
    System.out.println("私钥======"+keyMap.get("privateKey")); 
     String encryptString = encryptByPublicKey("{\\\"allBillList\\\":[{\\\"id\\\":\\\"264786\\\",\\\"billNo\\\":\\\"WB2021051700064\\\",\\\"billTypeId\\\":13,\\\"billTypeName\\\":\\\"定损维修\\\",\\\"vehicleNo\\\":\\\"京Q683976\\\",\\\"vehicleId\\\":\\\"532928\\\",\\\"vehicleOwner\\\":\\\"北京测试公司\\\",\\\"vehicleModelName\\\":\\\"宝马\\\",\\\"orderCar\\\":0,\\\"orderCarName\\\":\\\"短租\\\",\\\"cityId\\\":null,\\\"cityName\\\":\\\"北京\\\",\\\"deptId\\\":null,\\\"deptName\\\":\\\"北京测试\\\",\\\"nowCityId\\\":null,\\\"nowCityName\\\":null,\\\"nowDeptId\\\":null,\\\"nowDeptName\\\":null,\\\"belongCityId\\\":null,\\\"belongCityName\\\":\\\"北京\\\",\\\"belongDeptId\\\":null,\\\"belongDeptName\\\":\\\"知春路店\\\",\\\"costBelongAreaName\\\":\\\"知春路大片区\\\",\\\"costBelongCityName\\\":\\\"北京\\\",\\\"costBelongDeptName\\\":\\\"知春路店\\\",\\\"createTime\\\":\\\"2021-05-17 10:11\\\",\\\"modifyTime\\\":null,\\\"billStatusId\\\":109,\\\"billStatusName\\\":\\\"方案已通过\\\",\\\"createEmpName\\\":\\\"JD\\\",\\\"createEmpDeptName\\\":\\\"北京测试\\\",\\\"pickupType\\\":2,\\\"pickupTypeName\\\":\\\"上门\\\",\\\"isDelete\\\":0,\\\"isDeleteeName\\\":\\\"否\\\",\\\"garageId\\\":null}],\\\"totalCount\\\":1}\";\n","MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAnvGvwKuIfZdWilPI+nT/Pas1N6b3Jns7D9oK698h1j8yzmpD9KnM5hHCgl4toEVg4R4KEsJTTmUe9HU1dBTQby9TnBH5w5UeQgg/Mx5sJ3w5DyAPu2njOhU/5aoSInowpa5JLoba0YIzQWn++a/jhJs50T+Wt+xy3WEbF3QYN/Y7m0ZN1C70KXlX2xOLI8BL80BMqLF3Q1dIkvxLmxalJZiEnvkALWly8pERrvvz1YX6rKWOo1wtS5AJW1xrctnOf4saQi9/Jv0PRnkuFRo9BB1RZA/vV5kPt++szrCi7qDRCokAoQfn8enB1UJNED/tFWwqxpzZ+ic+C+FfLrxZ7nXocWMQWSojrIhY7+2TYT3fwO4ZvJoKlg71R6H+gSr2p0qBye+ELIeEr83UWMhvKrcAP0FpJcWpWpJaMKGo5yjUe4u7FBKF5j+O0GJCTfkxA8aw+KTZ/PnyoEI65PGD7i4XQWrvTPkyMcfMy9/dXd8efqzh5kg3kAauHvTBLcSpjRqCFT3pz6bK0azegrGPlIEPa3W5UzZ0MkhtM+6nbrOKgzuj27glwHRBNbhs8bllzVGU4+Zxv98lUp8VvPsVMweOHB4Zz/g+dLamHcMA0xLPPHZJRwvBbsm6rWd96Wcm0Y3ZyyIGMsj0AWPBjMvbHcBCJDFTxIMZ9GOAIMuU+lcCAwEAAQ=="); 
     System.out.println("密文======"+encryptString); String decryptString = decryptByPrivateKey(encryptString); 
    System.out.println("明文======"+decryptString); 
  } 
}

四、main方法测试结果:

公钥======MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAkFPpOKpa55rDkPMHuYcpy14rmuAv8Jn+kIwB81vzo154z+6yuzmxA9/7g/SQtZgkxsV323h3D6j1jYVMy+234noqx8Bj0UDVwrfFoG/M9mLnU/y5+CdlwGtVMTlfopfBsgZdJXQ72UpkFbVu87Ak7MwS95z3x7FtS4VlITcSM8tDs+qpmeMcbnVyCEyhKaxcqYyMvLwMqP4tE5UGH5YVBPBzfD4cKj/zXPqKAPhpQ+rtV/UBwgr+uS98Og07G1+KEjOd8aHbhksnLrNX1vz+WroR2sem14ke82k5VwAr5khb2bgeMsgwYCNB2yKOyYVfPq+13djAG2VR2TBCfQMm4WEI8rA54oKUDSi6XrYlH6ia+j0QXgmkF2dbj6zD8WGxfuIpfMxCHuPj5JvDgohxAMHT9KjxxVD9j5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PeyJdbseDk2m5iwXcI7vqg+Vs1NHdJqHPzNtKmIlAbnIwr0jjtAUqbOUVfx/retMA3j07hepNQxmkjm5HbEFBUdniSCpOi/+ajQpKjZTDZpbZ18GjBeLjYldavfC5dqj9EYFjMq6JmJ4Q3M+i2gHHMnEEiA81szhrdCYZRjviRfOWlyFELdxoyKqQf6Qi7ozRucEioKQzkArVVVS32JYssBJ57DyuO+hoDK/UBEinU3xsl38WRQZHdzIYL6sRJ2F0uE1VcGWKAA4WmxZtsQT1CYwtq+0/dRbzburHq9R97kZbUWShrkBaDEERI/DvWsdzZVNQhhVpKS/C/B5jiGXJ4hHHqaSg+ujMws0AP/D1o2DylG8a1D/z9Qnl0yQ/pdvSyl36DSKeulzgFNIQ4F7fUX1DI489ebUgE8q5Reja64TwYiolmC6hTHVVW9+llHkOYGiBA9/fT2BRyyXBXjm/wVFqWRGXWwLgD04bw==
明文======{\"allBillList\":[{\"id\":\"264786\",\"billNo\":\"WB2021051700064\",\"billTypeId\":13,\"billTypeName\":\"定损维修\",\"vehicleNo\":\"京Q683976\",\"vehicleId\":\"532928\",\"vehicleOwner\":\"北京测试公司\",\"vehicleModelName\":\"宝马\",\"orderCar\":0,\"orderCarName\":\"短租\",\"cityId\":null,\"cityName\":\"北京\",\"deptId\":null,\"deptName\":\"北京测试\",\"nowCityId\":null,\"nowCityName\":null,\"nowDeptId\":null,\"nowDeptName\":null,\"belongCityId\":null,\"belongCityName\":\"北京\",\"belongDeptId\":null,\"belongDeptName\":\"知春路店\",\"costBelongAreaName\":\"知春路大片区\",\"costBelongCityName\":\"北京\",\"costBelongDeptName\":\"知春路店\",\"createTime\":\"2021-05-17 10:11\",\"modifyTime\":null,\"billStatusId\":109,\"billStatusName\":\"方案已通过\",\"createEmpName\":\"JD\",\"createEmpDeptName\":\"北京测试\",\"pickupType\":2,\"pickupTypeName\":\"上门\",\"isDelete\":0,\"isDeleteeName\":\"否\",\"garageId\":null}],\"totalCount\":1}";
posted @ 2022-08-09 11:57  [奋斗]  阅读(1684)  评论(0编辑  收藏  举报