我想用DES方法数据库password字段密码,请哪位大虾教教我。批量加密所有用户的password.
解决方案 »
- 使用highcharts怎么去掉图表上那个官网标识链接?
- jquery 怎么实现自动填充···求解···
- java 中SQL语句问题
- 高手帮帮忙``~~~Jbuilder 如何连接mysql ~~~~~~~~~~~怎样配`~`~~~
- mysql怎么样在after trigger中更新列值
- 目前TOMCAT下用WEBWORK+SPRING,遇到严重: Error listenerStart,请大家指教
- JSP的一个runtime异常
- 请问大家用jsp一般都做什么项目啊?能否给我写点要求,让我无聊的时候写写(随便散点分)
- resin-2.1.9版如何加载到windowXP的服务里?
- tomcat运行时出现的问题,页面登陆后出现404
- hql语句报错 大家看看
- 老掉牙 问题 mysql 插入中文数据抱错!!
package DP.Business.Adapter;import javax.crypto.*;
import javax.crypto.spec.DESKeySpec;/**
* 加密解密类
*
* @author
* @version
*/
public class Eryptogram {
private final static String Algorithm = "DES";
private final static String BYTE_ENCODE = "GBK";
// 加密密匙
private final static String ENCODE = "12345678";
private SecretKey deskey; public Eryptogram() throws Exception {
DESKeySpec key = new DESKeySpec(this.ENCODE.getBytes(this.BYTE_ENCODE));
// 得到密钥
SecretKeyFactory skf = SecretKeyFactory.getInstance(this.Algorithm);
this.deskey = skf.generateSecret(key);
} public String Encrypt(String input) throws Exception {
// 开始加密处理
Cipher cipher = Cipher.getInstance(this.Algorithm);
cipher.init(Cipher.ENCRYPT_MODE, this.deskey);
byte[] cipherByte = cipher.doFinal(input.getBytes(this.BYTE_ENCODE));
return new sun.misc.BASE64Encoder().encode(cipherByte);
} public String Decode(String input) throws Exception {
// 解密处理
byte[] dec = new sun.misc.BASE64Decoder().decodeBuffer(input);
Cipher cipher = Cipher.getInstance(this.Algorithm);
cipher.init(Cipher.DECRYPT_MODE, this.deskey);
byte[] clearByte = cipher.doFinal(dec);
return new String(clearByte, this.BYTE_ENCODE);
} public static void main(String[] args) throws Exception {
Eryptogram des = new Eryptogram();
String ss = des.Encrypt("123456");
System.out.println("密文:" + ss);
System.out.println("明文:" + des.Decode(ss));
}}
用JAVA代码从数据库中读出所有的记录,再把密码字段的值丢给那个加密函数处理下,然后把处理的结果写回数据库就可以啦。别说怎么连数据库,怎么读数据都不知道吧。