This commit is contained in:
Carol 2021-09-01 13:30:04 +08:00
parent d212a43a62
commit 5b48828c77
8 changed files with 107 additions and 124 deletions

View File

@ -1,6 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="RemoteRepositoriesConfiguration"> <component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="spring" />
<option name="name" value="spring" />
<option name="url" value="http://10.1.15.172:8080/nexus/content/groups/public" />
</remote-repository>
<remote-repository> <remote-repository>
<option name="id" value="central" /> <option name="id" value="central" />
<option name="name" value="Central Repository" /> <option name="name" value="Central Repository" />
@ -16,6 +21,16 @@
<option name="name" value="JBoss Community repository" /> <option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" /> <option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository> </remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="central" />
<option name="url" value="http://10.1.15.172:8080/nexus/content/groups/public" />
</remote-repository>
<remote-repository>
<option name="id" value="apache" />
<option name="name" value="apache" />
<option name="url" value="http://10.1.15.172:8080/nexus/content/groups/public" />
</remote-repository>
<remote-repository> <remote-repository>
<option name="id" value="LocalMirrorId" /> <option name="id" value="LocalMirrorId" />
<option name="name" value="LocalMirrorId" /> <option name="name" value="LocalMirrorId" />

View File

@ -12,8 +12,6 @@ i
.gitattributes,2\4\24139dae656713ba861751fb2c2ac38839349a7a .gitattributes,2\4\24139dae656713ba861751fb2c2ac38839349a7a
9 9
README.md,8/e/8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d README.md,8/e/8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d
7
pom.xml,4/4/442292b8a7efeabbe4cc176709b833b1792140ec
k k
;src/main/java/site/cnkj/common/config/AsyncExecutePool.java,4\1\416390ba57649e9f4e6365934e9a6827cca3ffed ;src/main/java/site/cnkj/common/config/AsyncExecutePool.java,4\1\416390ba57649e9f4e6365934e9a6827cca3ffed
p p
@ -44,8 +42,6 @@ o
?src/main/java/site/cnkj/common/utils/data/MongoClientsInit.java,4/9/490c965ee8a02ce158895987485283bb4b666ab6 ?src/main/java/site/cnkj/common/utils/data/MongoClientsInit.java,4/9/490c965ee8a02ce158895987485283bb4b666ab6
g g
7src/main/java/site/cnkj/common/utils/date/DateUtil.java,1\5\157e0e9285b69e300624f35e79300c0ed6098936 7src/main/java/site/cnkj/common/utils/date/DateUtil.java,1\5\157e0e9285b69e300624f35e79300c0ed6098936
q
Asrc/main/java/site/cnkj/common/utils/file/FileEncryptDecrypt.java,e\a\eaa75651d9d6785c2bd75843529d61a722450af5
g g
7src/main/java/site/cnkj/common/utils/file/FileUtil.java,d\f\df021943680d67b4f49e98599f4bb0e86803c590 7src/main/java/site/cnkj/common/utils/file/FileUtil.java,d\f\df021943680d67b4f49e98599f4bb0e86803c590
m m
@ -57,8 +53,6 @@ e
` `
0src/main/java/site/cnkj/common/utils/io/DES.java,6\4\644b718a1d63acca44c411c399624e16ce98e11c 0src/main/java/site/cnkj/common/utils/io/DES.java,6\4\644b718a1d63acca44c411c399624e16ce98e11c
g g
7src/main/java/site/cnkj/common/utils/io/RSAEncrypt.java,8\2\82864735cd8af377e6ad061ae189505a1e3e9d7c
g
7src/main/java/site/cnkj/common/utils/io/StringUtil.java,a\4\a43b6e3feeba3336586237a758acfa97b791be5b 7src/main/java/site/cnkj/common/utils/io/StringUtil.java,a\4\a43b6e3feeba3336586237a758acfa97b791be5b
k k
;src/main/java/site/cnkj/common/utils/logger/LoggerUtil.java,4\f\4ffd3a6de814df96de78c74e6c16f964b4fe9a03 ;src/main/java/site/cnkj/common/utils/logger/LoggerUtil.java,4\f\4ffd3a6de814df96de78c74e6c16f964b4fe9a03

View File

@ -4,21 +4,14 @@
<option name="autoReloadType" value="ALL" /> <option name="autoReloadType" value="ALL" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="52b7c556-aac6-402c-b840-5f2564f1f5d7" name="Default" comment="change MongoClientInit and fix some bug."> <list default="true" id="8ab3ef3f-5475-495f-a0ee-8551c01ff741" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.idea/CommonUtil.iml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/jarRepositories.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/jarRepositories.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/codeStyles/codeStyleConfig.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/sonarlint/issuestore/4/4/442292b8a7efeabbe4cc176709b833b1792140ec" beforeDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/intellij-javadocs-4.0.1.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/sonarlint/issuestore/8/2/82864735cd8af377e6ad061ae189505a1e3e9d7c" beforeDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/jarRepositories.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/sonarlint/issuestore/e/a/eaa75651d9d6785c2bd75843529d61a722450af5" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/compiler.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/compiler.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/encodings.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/encodings.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/sonarlint/issuestore/4/9/490c965ee8a02ce158895987485283bb4b666ab6" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/sonarlint/issuestore/4/9/490c965ee8a02ce158895987485283bb4b666ab6" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/sonarlint/issuestore/b/b/bb173f9557479135e0f1bcd9c6c5f7b4ae5f77e8" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/sonarlint/issuestore/c/1/c131e8dffaaace66f248f9071023b60be7b277a4" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/sonarlint/issuestore/c/1/c131e8dffaaace66f248f9071023b60be7b277a4" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/sonarlint/issuestore/e/a/eaaa4be2d68e0a2d603579b394cb7c0ee6bb6df5" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/sonarlint/issuestore/index.pb" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/sonarlint/issuestore/index.pb" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/sonarlint/issuestore/index.pb" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/sonarlint/issuestore/index.pb" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/vcs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/site/cnkj/common/utils/io/RSAEncrypt.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/site/cnkj/common/utils/io/RSAEncrypt.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -93,13 +86,6 @@
<detection-done>true</detection-done> <detection-done>true</detection-done>
<sorting>DEFINITION_ORDER</sorting> <sorting>DEFINITION_ORDER</sorting>
</component> </component>
<component name="MavenImportPreferences">
<option name="generalSettings">
<MavenGeneralSettings>
<option name="alwaysUpdateSnapshots" value="true" />
</MavenGeneralSettings>
</option>
</component>
<component name="MavenProjectNavigator"> <component name="MavenProjectNavigator">
<treeState> <treeState>
<expand> <expand>
@ -388,7 +374,7 @@
<property name="SONARLINT_PRECOMMIT_ANALYSIS" value="true" /> <property name="SONARLINT_PRECOMMIT_ANALYSIS" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" /> <property name="WebServerToolWindowFactoryState" value="false" />
<property name="aspect.path.notification.shown" value="true" /> <property name="aspect.path.notification.shown" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" /> <property name="last_opened_file_path" value="$PROJECT_DIR$/../../csgl/hettrmsservice" />
<property name="node.js.detected.package.eslint" value="true" /> <property name="node.js.detected.package.eslint" value="true" />
<property name="node.js.detected.package.standard" value="true" /> <property name="node.js.detected.package.standard" value="true" />
<property name="node.js.path.for.package.eslint" value="project" /> <property name="node.js.path.for.package.eslint" value="project" />

8
CommonUtil.iml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="CheckStyle-IDEA-Module">
<option name="configuration">
<map />
</option>
</component>
</module>

View File

@ -1,7 +1,7 @@
package site.cnkj.common.utils.io; package site.cnkj.common.utils.io;
import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.bouncycastle.jce.provider.BouncyCastleProvider;
import sun.misc.BASE64Decoder; import org.apache.commons.codec.binary.Base64;
import javax.crypto.BadPaddingException; import javax.crypto.BadPaddingException;
import javax.crypto.Cipher; import javax.crypto.Cipher;
@ -18,15 +18,19 @@ import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec; import java.security.spec.X509EncodedKeySpec;
/**
* RSA非对称数据加解密
* @version 1.0 created by LXW on 2019/4/15 15:31
*/
public class RSAEncrypt { public class RSAEncrypt {
private static final String DEFAULT_PUBLIC_KEY= public static final String DEFAULT_PUBLIC_KEY=
"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQChDzcjw/rWgFwnxunbKp7/4e8w" + "\r" + "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQChDzcjw/rWgFwnxunbKp7/4e8w" + "\r" +
"/UmXx2jk6qEEn69t6N2R1i/LmcyDT1xr/T2AHGOiXNQ5V8W4iCaaeNawi7aJaRht" + "\r" + "/UmXx2jk6qEEn69t6N2R1i/LmcyDT1xr/T2AHGOiXNQ5V8W4iCaaeNawi7aJaRht" + "\r" +
"Vx1uOH/2U378fscEESEG8XDqll0GCfB1/TjKI2aitVSzXOtRs8kYgGU78f7VmDNg" + "\r" + "Vx1uOH/2U378fscEESEG8XDqll0GCfB1/TjKI2aitVSzXOtRs8kYgGU78f7VmDNg" + "\r" +
"XIlk3gdhnzh+uoEQywIDAQAB" + "\r"; "XIlk3gdhnzh+uoEQywIDAQAB" + "\r";
private static final String DEFAULT_PRIVATE_KEY= public static final String DEFAULT_PRIVATE_KEY=
"MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAKEPNyPD+taAXCfG" + "\r" + "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAKEPNyPD+taAXCfG" + "\r" +
"6dsqnv/h7zD9SZfHaOTqoQSfr23o3ZHWL8uZzINPXGv9PYAcY6Jc1DlXxbiIJpp4" + "\r" + "6dsqnv/h7zD9SZfHaOTqoQSfr23o3ZHWL8uZzINPXGv9PYAcY6Jc1DlXxbiIJpp4" + "\r" +
"1rCLtolpGG1XHW44f/ZTfvx+xwQRIQbxcOqWXQYJ8HX9OMojZqK1VLNc61GzyRiA" + "\r" + "1rCLtolpGG1XHW44f/ZTfvx+xwQRIQbxcOqWXQYJ8HX9OMojZqK1VLNc61GzyRiA" + "\r" +
@ -42,6 +46,8 @@ public class RSAEncrypt {
"Fae7oAqkMAd3xCNY6ec180tAe57hZ6kS+SYLKwb4gGzYaCxc22vMtYksXHtUeamo" + "\r" + "Fae7oAqkMAd3xCNY6ec180tAe57hZ6kS+SYLKwb4gGzYaCxc22vMtYksXHtUeamo" + "\r" +
"1NMLzI2ZfUoX" + "\r"; "1NMLzI2ZfUoX" + "\r";
/** /**
* 私钥 * 私钥
*/ */
@ -85,170 +91,144 @@ public class RSAEncrypt {
e.printStackTrace(); e.printStackTrace();
} }
if (keyPairGen != null){ if (keyPairGen != null){
keyPairGen.initialize(1024, new SecureRandom()); keyPairGen.initialize(2048, new SecureRandom());
KeyPair keyPair= keyPairGen.generateKeyPair(); KeyPair keyPair= keyPairGen.generateKeyPair();
this.privateKey= (RSAPrivateKey) keyPair.getPrivate(); this.privateKey= (RSAPrivateKey) keyPair.getPrivate();
this.publicKey= (RSAPublicKey) keyPair.getPublic(); this.publicKey= (RSAPublicKey) keyPair.getPublic();
} }
} }
private StringBuilder loadKey(InputStream in) throws IOException {
BufferedReader br= new BufferedReader(new InputStreamReader(in));
String readLine= null;
StringBuilder sb= new StringBuilder();
while((readLine= br.readLine())!=null){
if(readLine.charAt(0)!='-'){
sb.append(readLine);
sb.append('\r');
}
}
return sb;
}
/** /**
* 从文件中输入流中加载公钥 * 从文件中输入流中加载公钥
* @param in 公钥输入流 * @param in 公钥输入流
* @throws Exception 加载公钥时产生的异常 * @throws IOException e
* @throws NoSuchAlgorithmException e
* @throws InvalidKeySpecException e
*/ */
public void loadPublicKey(InputStream in) throws Exception{ public void loadPublicKey(InputStream in) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
try { loadPublicKey(loadKey(in).toString());
BufferedReader br= new BufferedReader(new InputStreamReader(in));
String readLine= null;
StringBuilder sb= new StringBuilder();
while((readLine= br.readLine())!=null){
if(readLine.charAt(0)=='-'){
continue;
}else{
sb.append(readLine);
sb.append('\r');
}
}
loadPublicKey(sb.toString());
} catch (IOException e) {
throw new Exception("公钥数据流读取错误");
} catch (NullPointerException e) {
throw new Exception("公钥输入流为空");
}
} }
/** /**
* 从字符串中加载公钥 * 从字符串中加载公钥
* @param publicKeyStr 公钥数据字符串 * @param publicKeyStr 公钥数据字符串
* @throws Exception 加载公钥时产生的异常 * @throws NoSuchAlgorithmException e
* @throws InvalidKeySpecException e
*/ */
public void loadPublicKey(String publicKeyStr) throws Exception{ public void loadPublicKey(String publicKeyStr) throws NoSuchAlgorithmException, InvalidKeySpecException {
try { byte[] buffer= Base64.decodeBase64(publicKeyStr);
BASE64Decoder base64Decoder= new BASE64Decoder(); KeyFactory keyFactory= KeyFactory.getInstance("RSA");
byte[] buffer= base64Decoder.decodeBuffer(publicKeyStr); X509EncodedKeySpec keySpec= new X509EncodedKeySpec(buffer);
KeyFactory keyFactory= KeyFactory.getInstance("RSA"); this.publicKey= (RSAPublicKey) keyFactory.generatePublic(keySpec);
X509EncodedKeySpec keySpec= new X509EncodedKeySpec(buffer);
this.publicKey= (RSAPublicKey) keyFactory.generatePublic(keySpec);
} catch (NoSuchAlgorithmException e) {
throw new Exception("无此算法");
} catch (InvalidKeySpecException e) {
throw new Exception("公钥非法");
} catch (IOException e) {
throw new Exception("公钥数据内容读取错误");
} catch (NullPointerException e) {
throw new Exception("公钥数据为空");
}
} }
/** /**
* 从文件中加载私钥 * 从文件中加载私钥
* @param in 输入流 * @param in 输入流
* @return 是否成功 * @throws NoSuchAlgorithmException e
* @throws Exception * @throws InvalidKeySpecException e
* @throws IOException e
*/ */
public void loadPrivateKey(InputStream in) throws Exception{ public void loadPrivateKey(InputStream in) throws NoSuchAlgorithmException, InvalidKeySpecException, IOException{
try { loadPrivateKey(loadKey(in).toString());
BufferedReader br= new BufferedReader(new InputStreamReader(in));
String readLine= null;
StringBuilder sb= new StringBuilder();
while((readLine= br.readLine())!=null){
if(readLine.charAt(0)=='-'){
continue;
}else{
sb.append(readLine);
sb.append('\r');
}
}
loadPrivateKey(sb.toString());
} catch (IOException e) {
throw new Exception("私钥数据读取错误");
} catch (NullPointerException e) {
throw new Exception("私钥输入流为空");
}
} }
public void loadPrivateKey(String privateKeyStr) throws Exception{ public void loadPrivateKey(String privateKeyStr) throws NoSuchAlgorithmException, InvalidKeySpecException {
try { try {
BASE64Decoder base64Decoder= new BASE64Decoder(); byte[] buffer= Base64.decodeBase64(privateKeyStr);
byte[] buffer= base64Decoder.decodeBuffer(privateKeyStr);
PKCS8EncodedKeySpec keySpec= new PKCS8EncodedKeySpec(buffer); PKCS8EncodedKeySpec keySpec= new PKCS8EncodedKeySpec(buffer);
KeyFactory keyFactory= KeyFactory.getInstance("RSA"); KeyFactory keyFactory= KeyFactory.getInstance("RSA");
this.privateKey= (RSAPrivateKey) keyFactory.generatePrivate(keySpec); this.privateKey= (RSAPrivateKey) keyFactory.generatePrivate(keySpec);
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
throw new Exception("无此算法"); throw new NoSuchAlgorithmException("无此算法");
} catch (InvalidKeySpecException e) { } catch (InvalidKeySpecException e) {
throw new Exception("私钥非法"); throw new InvalidKeySpecException("私钥非法");
} catch (IOException e) {
throw new Exception("私钥数据内容读取错误");
} catch (NullPointerException e) { } catch (NullPointerException e) {
throw new Exception("私钥数据为空"); throw new NullPointerException("私钥数据为空");
} }
} }
/** /**
* 加密过程 * 加密过程
* @param publicKey 公钥 * @param publicKey 公钥
* @param plainTextData 明文数据 * @param plainTextData 明文数据
* @return * @return 加密后字节
* @throws Exception 加密过程中的异常信息 * @throws NoSuchAlgorithmException e
* @throws InvalidKeyException e
* @throws IllegalBlockSizeException e
* @throws BadPaddingException e
* @throws NoSuchPaddingException e
*/ */
public byte[] encrypt(RSAPublicKey publicKey, byte[] plainTextData) throws Exception{ public byte[] encrypt(RSAPublicKey publicKey, byte[] plainTextData) throws NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, NoSuchPaddingException {
if(publicKey== null){ if(publicKey== null){
throw new Exception("加密公钥为空, 请设置"); throw new NullPointerException("加密公钥为空, 请设置");
} }
Cipher cipher= null; Cipher cipher= null;
try { try {
cipher= Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding", new BouncyCastleProvider()); cipher= Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding", new BouncyCastleProvider());
cipher.init(Cipher.ENCRYPT_MODE, publicKey); cipher.init(Cipher.ENCRYPT_MODE, publicKey);
byte[] output= cipher.doFinal(plainTextData); return cipher.doFinal(plainTextData);
return output;
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
throw new Exception("无此加密算法"); throw new NoSuchAlgorithmException("无此加密算法");
} catch (NoSuchPaddingException e) {
e.printStackTrace();
return null;
} catch (InvalidKeyException e) { } catch (InvalidKeyException e) {
throw new Exception("加密公钥非法,请检查"); throw new InvalidKeyException("加密公钥非法,请检查");
} catch (IllegalBlockSizeException e) { } catch (IllegalBlockSizeException e) {
throw new Exception("明文长度非法"); throw new IllegalBlockSizeException("明文长度非法");
} catch (BadPaddingException e) { } catch (BadPaddingException e) {
throw new Exception("明文数据已损坏"); throw new BadPaddingException("明文数据已损坏");
} catch (Exception e){ } catch (NoSuchPaddingException e) {
e.printStackTrace(); throw new NoSuchPaddingException("无此类填充");
return null;
} }
} }
/** /**
* 解密过程 * 解密过程
* @param privateKey 私钥 * @param privateKey 私钥
* @param cipherData 密文数据 * @param cipherData 密文数据
* @return 明文 * @return 明文
* @throws Exception 解密过程中的异常信息 * @throws NoSuchAlgorithmException e
* @throws NoSuchPaddingException e
* @throws InvalidKeyException e
* @throws IllegalBlockSizeException e
* @throws BadPaddingException e
*/ */
public byte[] decrypt(RSAPrivateKey privateKey, byte[] cipherData) throws Exception{ public byte[] decrypt(RSAPrivateKey privateKey, byte[] cipherData) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
if (privateKey== null){ if (privateKey== null){
throw new Exception("解密私钥为空, 请设置"); throw new NullPointerException("解密私钥为空, 请设置");
} }
Cipher cipher= null; Cipher cipher= null;
try { try {
cipher= Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding", new BouncyCastleProvider()); cipher= Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding", new BouncyCastleProvider());
cipher.init(Cipher.DECRYPT_MODE, privateKey); cipher.init(Cipher.DECRYPT_MODE, privateKey);
byte[] output= cipher.doFinal(cipherData); return cipher.doFinal(cipherData);
return output;
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
throw new Exception("无此解密算法"); throw new NoSuchAlgorithmException("无此解密算法");
} catch (NoSuchPaddingException e) { } catch (NoSuchPaddingException e) {
e.printStackTrace(); throw new NoSuchPaddingException("无此类填充");
return null;
}catch (InvalidKeyException e) { }catch (InvalidKeyException e) {
throw new Exception("解密私钥非法,请检查"); throw new InvalidKeyException("解密私钥非法,请检查");
} catch (IllegalBlockSizeException e) { } catch (IllegalBlockSizeException e) {
throw new Exception("密文长度非法"); throw new IllegalBlockSizeException("密文长度非法");
} catch (BadPaddingException e) { } catch (BadPaddingException e) {
throw new Exception("密文数据已损坏"); throw new BadPaddingException("密文数据已损坏");
} }
} }