解密方式如何在数据库中用SQL实现 10
以下是加密方式,现在要用SQL在数据库中实现解密,能实现吗?怎么实现?谢谢!//加密密码publicfinalstaticStringenPass(Stringpassw...
以下是加密方式,现在要用SQL在数据库中实现解密,能实现吗?怎么实现?谢谢!
// 加密密码
public final static String enPass(String password) {
try {
SecretKey key = readKey();
Cipher cip = Cipher.getInstance("DESede");
cip.init(Cipher.ENCRYPT_MODE, key);
byte[] cipBytes = cip.doFinal(password.getBytes());
String sblob = new BASE64Encoder().encode(cipBytes);
return sblob;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "";
}
}
private final static SecretKey readKey() {
try {
String skey = "changxiaohui_changxiaohui_changxiaohui";
byte[] bs = skey.getBytes("UTF-8");
KeySpec pbe = new DESedeKeySpec(bs);
SecretKeyFactory skf = SecretKeyFactory.getInstance("DESede");
SecretKey key = skf.generateSecret(pbe);
return key;
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return null;
} 展开
// 加密密码
public final static String enPass(String password) {
try {
SecretKey key = readKey();
Cipher cip = Cipher.getInstance("DESede");
cip.init(Cipher.ENCRYPT_MODE, key);
byte[] cipBytes = cip.doFinal(password.getBytes());
String sblob = new BASE64Encoder().encode(cipBytes);
return sblob;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "";
}
}
private final static SecretKey readKey() {
try {
String skey = "changxiaohui_changxiaohui_changxiaohui";
byte[] bs = skey.getBytes("UTF-8");
KeySpec pbe = new DESedeKeySpec(bs);
SecretKeyFactory skf = SecretKeyFactory.getInstance("DESede");
SecretKey key = skf.generateSecret(pbe);
return key;
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return null;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询