【add】添加工具类RSA解密方法
This commit is contained in:
+20
-5
@@ -1,5 +1,7 @@
|
|||||||
package com.jero.common.util;
|
package com.jero.common.util;
|
||||||
|
|
||||||
|
import cn.hutool.crypto.asymmetric.KeyType;
|
||||||
|
import cn.hutool.crypto.asymmetric.RSA;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import com.jero.common.constant.CommonConstant;
|
import com.jero.common.constant.CommonConstant;
|
||||||
import com.jero.common.constant.DataBaseConstant;
|
import com.jero.common.constant.DataBaseConstant;
|
||||||
@@ -10,14 +12,16 @@ import org.springframework.util.FileCopyUtils;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.*;
|
||||||
import java.io.File;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.io.IOException;
|
import java.security.KeyFactory;
|
||||||
import java.io.InputStream;
|
import java.security.PrivateKey;
|
||||||
|
import java.security.spec.PKCS8EncodedKeySpec;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DatabaseMetaData;
|
import java.sql.DatabaseMetaData;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@@ -219,6 +223,17 @@ public class CommonUtils {
|
|||||||
boolean isExists = fileNameList.stream().anyMatch(name -> fileName.substring(0,fileName.lastIndexOf('.')).contains(name)||fileName.substring(fileName.lastIndexOf('.')).equals(name));
|
boolean isExists = fileNameList.stream().anyMatch(name -> fileName.substring(0,fileName.lastIndexOf('.')).contains(name)||fileName.substring(fileName.lastIndexOf('.')).equals(name));
|
||||||
return isExists;
|
return isExists;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* RSA 使用私钥解密
|
||||||
|
* @date 2021/4/15 16:11
|
||||||
|
* @param str 待解密的字符串
|
||||||
|
* @param RSAPrivateKey 私钥
|
||||||
|
* @return String 解密后的字符串
|
||||||
|
*/
|
||||||
|
public static String decryptBtRsaPriKey(String str,String RSAPrivateKey) throws Exception {
|
||||||
|
RSA rsa = new RSA(RSAPrivateKey, null);
|
||||||
|
byte[] decrypt = rsa.decrypt(str, KeyType.PrivateKey);
|
||||||
|
return new String(decrypt);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user