java明文解密源代码 java 加解密开源工具类( 八 )


}
}
谁有用js加密,用java对应解密的 源代码script language="javascript"
var str;
function showUnico(){
if(document.getElementById("before").value.length 0){
str = escape(document.getElementById("before").value);
document.getElementById("after").value = https://www.04ip.com/post/str;
}
else alert("请输入要加密的代码");
}
function showHtml(){
if(document.getElementById("after").value.length 0){
str = unescape(document.getElementById("after").value);
document.getElementById("before").value = https://www.04ip.com/post/str;
}
else alert("请输入要解密的代码");
}
function clearBoth(){
document.getElementById("before").valuehttps://www.04ip.com/post/= "";
document.getElementById("after").valuehttps://www.04ip.com/post/= "";
}
/script
body
center
table
tr
th加密前/th
th加密后/th
/tr
tr
td
textarea id="before" style="width: 200px; height: 174px"/textarea
/td
td
textarea id="after" style="width: 200px; height: 174px"/textarea
/td
/tr
/table
br
input type="button" value="https://www.04ip.com/post/加密" onclick="showUnico()"
input type="button" value="https://www.04ip.com/post/解密" onclick="showHtml()"
input type="button" value="https://www.04ip.com/post/全部清空" onclick="clearBoth()"
/center
/body
java实现ase加密解密这个算法java SDK自带的额 参考代码如下:
/**解密
* @param content待解密内容
* @param password 解密密钥
* @return
*/
public static byte[] decrypt(byte[] content, String password) {
try {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
kgen.init(128, new SecureRandom(password.getBytes()));
SecretKey secretKey = kgen.generateKey();
byte[] enCodeFormat = secretKey.getEncoded();
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");
Cipher cipher = Cipher.getInstance("AES");// 创建密码器
cipher.init(Cipher.DECRYPT_MODE, key);// 初始化
byte[] result = cipher.doFinal(content);
return result; // 加密
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
}
return null;
}
/**
* 加密
*
* @param content 需要加密的内容
* @param password加密密码
* @return
*/
public static byte[] encrypt(String content, String password) {
try {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
kgen.init(128, new SecureRandom(password.getBytes()));
SecretKey secretKey = kgen.generateKey();
byte[] enCodeFormat = secretKey.getEncoded();
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");
Cipher cipher = Cipher.getInstance("AES");// 创建密码器
byte[] byteContent = content.getBytes("utf-8");
cipher.init(Cipher.ENCRYPT_MODE, key);// 初始化
byte[] result = cipher.doFinal(byteContent);
return result; // 加密
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
}
return null;
}
图像界面的话就不说了
【java明文解密源代码 java 加解密开源工具类】

推荐阅读