我想用DES方法数据库password字段密码,请哪位大虾教教我。批量加密所有用户的password.
  

解决方案 »

  1.   

    我这里有了一个加密、解密类<Eryptogram.java>,怎么添加方法实现数据库password字段全部加密,请教各位:
    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));
    }}
      

  2.   

    楼上几位已经给出方法啦。
    用JAVA代码从数据库中读出所有的记录,再把密码字段的值丢给那个加密函数处理下,然后把处理的结果写回数据库就可以啦。别说怎么连数据库,怎么读数据都不知道吧。