servlet的Servlet.service()LoginController抛出了异常java.lang.ClassNotFoundException:Decoder.BASE64Encoder

时间:2014-11-20 07:59:56

标签: java java-ee servlets

servlet的Servlet.service()LoginController引发异常java.lang.ClassNotFoundException:Decoder.BASE64Encoder

try{
    String pass=request.getParameter("password");
    String plainData=pass,cipherText,decryptedText;

    KeyGenerator keyGen = KeyGenerator.getInstance("AES"); 
    keyGen.init(128); 

    SecretKey secretKey = keyGen.generateKey(); 
    Cipher aesCipher = Cipher.getInstance("AES"); 
    aesCipher.init(Cipher.ENCRYPT_MODE,secretKey); 

    byte[] byteDataToEncrypt = plainData.getBytes(); 
    byte[] byteCipherText = aesCipher.doFinal(byteDataToEncrypt); 

    cipherText=new BASE64Encoder().encode(byteCipherText);

    System.out.println("cipherText"+cipherText);
    ld=new LoginDao();

    String encryptedpass=ld.validatepass(cipherText);
    System.out.println();
}
catch(Exception ex){

}

1 个答案:

答案 0 :(得分:2)

在您的Web项目的lib目录中添加commons-codec jar并使用

new Base64().encodeToString(String)编码

您的Web应用程序war文件结构类似于

WebContent
    --- WEB-INF
         ----web.xml (Deployment Descriptor)
         ---- lib 
                --- Add your libraries here i.e.common-codec.jar and others