帮我看一下这个Des加解密类...
编译没有问题,加密也没有问题,就是解密的时候,出现:
java.lang.RuntimeException: Error initializing SqlMap class. Cause: java.lang.
RuntimeException: Error initializing SqlMap class. Cause:
javax.crypto.BadPaddingException: Given final block not properly padded
不知道如何解决,
test.jsp文件
**************************************************************
<%@ page import= "net.moftree.client.DesEncrypt " contentType= "text/html;charset=UTF-8 "
errorPage= "/app/errorHandler.jsf " %>
DesEncrypt des = new DesEncrypt( "19771205 ");
String str1 = "dmhwxf ";
//DES加密
String str2=des.getEncString(str1);
out.println( "根据密钥加密后的密文: "+str2+ ": ");
String str3= "9UKtP8c4gu4= ";//
out.println( "根据密钥解密后的明文: "+des.getDesString(str3));
我每刷一次test.jsp 相同的key和str1所生成的 str2值都不一样,我用生成的str3值写到str3里面,然后再解密,就出现了上面的问题.
DesEncrypt.java文件
package net.moftree.client;
import java.security.*;
import javax.crypto.*;
import sun.misc.*;
public class DesEncrypt
{
Key key;
public DesEncrypt(String str)
{
getKey(str);
}
public void getKey(String strKey)
{
try
{
KeyGenerator _generator = KeyGenerator.getInstance( "DES ");
_generator.init(new SecureRandom(strKey.getBytes()));
this.key = _generator.generateKey();
_generator = null;
}
catch (Exception e)
{
throw new RuntimeException( "Error initializing SqlMap class. Cause: "+e);
}
}
public String getEncString(String strMing)
{
byte[] byteMi = null;
byte[] byteMing = null;
String strMi = " ";
BASE64Encoder base64en = new BASE64Encoder();