MCPcopy Create free account
hub / github.com/diyhi/bbs / decrypt

Method decrypt

src/main/java/cms/utils/AES.java:69–93  ·  view source on GitHub ↗

解密 @param data 数据 @param key 密码 @param iv 初始化向量 @return

(String data,String key,String iv)

Source from the content-addressed store, hash-verified

67 * @return
68 */
69 public static String decrypt(String data,String key,String iv) {
70 if(iv == null || iv.length() != 16){//如果iv为空,则使用默认值
71 iv = IV_DEFAULT;
72 }
73
74 try {
75 String text = Base64.decode(data.getBytes());
76
77 byte[] by = ConvertTobyte(text);
78 Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
79 SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES");
80 IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes());
81
82 cipher.init(Cipher.DECRYPT_MODE, keyspec, ivspec);
83
84 byte[] original = cipher.doFinal(by);
85 String originalString = new String(original);
86 return originalString.trim();
87 }catch (Exception e) {
88 if (logger.isErrorEnabled()) {
89 logger.error("解密",e);
90 }
91 }
92 return null;
93 }
94
95 private static byte[] ConvertTobyte(String data) {
96 int maxLength = data.length();

Callers 4

fileDownloadMethod · 0.95
getDatabaseParameterMethod · 0.45
addMethod · 0.45

Calls 3

decodeMethod · 0.95
ConvertTobyteMethod · 0.95
initMethod · 0.80

Tested by 1

getDatabaseParameterMethod · 0.36