sunjianghua2018 2018-03-27 07:42 采纳率: 100%
浏览 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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog
    • ¥15 Excel发现不可读取的内容