📄 encryptexception.java
字号:
package com.emk.manage.exception;
import com.common.util.PropertyLoader;
import com.emk.manage.Constants;
/**
* 加密、解密、数字签名、信息摘要异常处理类,集中将所有的加密解密过程种的异常在这里处理
* @author 李伟光
*/
public class EncryptException extends RuntimeException {
private static final String INVALIDKEY="java.security.InvalidKeyException";
private static final String NOSUCHALGORITHM="java.security.NoSuchAlgorithmException";
private static final String NOSUCHPADDING="javax.crypto.NoSuchPaddingException";
private static final String ILLEGALBLOCKSIZE="javax.crypto.IllegalBlockSizeException";
private static final String BADPADDING="javax.crypto.BadPaddingException";
private static final String IO="java.io.IOException";
private static final String UNSUPPORTEDENCODING="java.io.UnsupportedEncodingException";
private static final String SIGNATURE ="java.security.SignatureException";
private static final String FILENOTFOUND="java.io.FileNotFoundException";
private static final String INVALIDKEYSPEC ="java.security.spec.InvalidKeySpecException";
private static final String INVALIDALGORITHMPARAMETER="java.security.InvalidAlgorithmParameterException";
private static final String ILLEGALSTATE="java.lang.IllegalStateException";
private static final String CLASSNOTFOUND="java.lang.ClassNotFoundException";
private static final String NEGATIVEARRAYSIZE="java.lang.NegativeArraySizeException";
private String message;//信息代码
private String messageFileName;//要调用的信息文件名
/**
* 返回要调用的信息文件名
* @return 要调用的信息文件名
*/
public String getMessageFileName() {
return messageFileName;
}
/**
* 设置要调用的信息文件名
* @param messageFileName 要调用的信息文件名
*/
public void setMessageFileName(String messageFileName) {
this.messageFileName = messageFileName;
}
/**
* 返回信息代码
* @return 信息代码
*/
public String getMessage() {
return message;
}
/**
* 初始化构造器,辨认异常的类型,并设置错误代码
* @param e 真正异常类
*/
public EncryptException(Exception e){
super();
String exceptionName=e.getClass().getName();
if(BADPADDING.equals(exceptionName)){
this.message="resource_EncryptException_001";//坏填充模式
}else if(ILLEGALBLOCKSIZE.equals(exceptionName)){
this.message="resource_EncryptException_002";//无效的块大小
}else if(INVALIDKEY.equals(exceptionName)){
this.message="resource_EncryptException_003";//无效的键
}else if(IO.equals(exceptionName)){
this.message="resource_EncryptException_004";//读写文件失败
}else if(NOSUCHALGORITHM.equals(exceptionName)){
this.message="resource_EncryptException_005";//无此加密算法
}else if(NOSUCHPADDING.equals(exceptionName)){
this.message="resource_EncryptException_006";//无此填充模式
}else if(UNSUPPORTEDENCODING.equals(exceptionName)){
this.message="resource_EncryptException_007";//不支持的字符编码方式
}else if(SIGNATURE.equals(exceptionName)){
this.message="resource_EncryptException_008";//数字签名异常
}else if(FILENOTFOUND.equals(exceptionName)){
this.message="resource_EncryptException_009";//找不到文件
}else if(INVALIDKEYSPEC.equals(exceptionName)){
this.message="resource_EncryptException_010";//无效的键描述
}else if(INVALIDALGORITHMPARAMETER.equals(exceptionName)){
this.message="resource_EncryptException_011";//无效的算法参数
}else if(ILLEGALSTATE.equals(exceptionName)){
this.message="resource_EncryptException_012";//非法的语句描述
}else if(CLASSNOTFOUND.equals(exceptionName)){
this.message="resource_EncryptException_013";//找不到类
}else if(NEGATIVEARRAYSIZE.equals(exceptionName)){
this.message="resource_EncryptException_014";//非加密数据解密错误
}
else{
this.message="resource_001";//未知错误
}
}
/**
* 返回处理好的错误提示信息
*/
public String toString(){
return PropertyLoader.getPptValue(Constants.MESSAGE_FILENAME,getMessage());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -