sunjianghua2018 2018-03-27 07:42 采纳率: 60%
浏览 597
已结题

跪求大神解答EDS的问题

package testNumber2;

import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.Security;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;

public class EncrypDES {
// KeyGenerator 提供对称密匙生成器的功能,支持各种算法
private KeyGenerator keygen;
// SecretKey 负责保存对称密匙
private SecretKey deskey;
// Cipher 负责完成加密或解密的结果
private Cipher c;
// 改字节数组负责保存加密的结果
private byte[] cipherByte;

public EncrypDES() throws NoSuchAlgorithmException, NoSuchPaddingException {
    Security.addProvider(new com.sun.crypto.provider.SunJCE());
    keygen = KeyGenerator.getInstance("DES");
    deskey = keygen.generateKey();
    c = Cipher.getInstance("DES");
}

public byte[] Encrytor(String str) throws InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
    c.init(Cipher.ENCRYPT_MODE, deskey);
    byte[] src = str.getBytes();
    cipherByte = c.doFinal(src);
    return cipherByte;
}

public byte[] Decryptor(byte[] buff) throws InvalidKeyException,IllegalBlockSizeException,BadPaddingException {
    c.init(Cipher.DECRYPT_MODE, deskey);
    cipherByte = c.doFinal(buff);
    return cipherByte;
}

public static void main(String[] args) throws Exception {
    EncrypDES de1 = new EncrypDES ();
    String msg = "郭xx-搞笑相声全集";
    byte[] encontent = de1.Encrytor(msg);

// byte[] decontent = de1.Decryptor(encontent);
System.out.println("明文是:"+msg);
String s = new String(encontent);
System.out.println("加密后:"+s);

    System.out.println("aaaa  "+s);
    byte[] encontent2 = s.getBytes();
    System.out.println("bbbb  "+encontent2);
    byte[] decontent2 = de1.Decryptor(encontent2);

// System.out.println("解密后:"+new String(decontent));
System.out.println("解密后:"+new String(decontent2));

}

}
用EDS给注册时候的密码加密保存数据库,登陆时输入密码跟取出数据库的加密码解码后比较,用这上面的方法哪里不对,请大神帮忙

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料