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

标签 java jakarta-ee servlets

servlet LoginController 的 Servlet.service() 抛出异常 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){

}

最佳答案

在 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

关于java - Servlet LoginController 的 Servlet.service() 抛出异常 java.lang.ClassNotFoundException : Decoder. BASE64Encoder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27034508/

相关文章:

java - Spring 3.0找不到applicationcontext.xml

java - 多个servlet转发后如何从servlet/jsp获取原始请求url

java - 如何在Gradle中启用Java代理调试?

java - Swing 应用程序框架 session 存储

java - 如何使用确认密码验证密码然后重定向?

java - Java EE 5 和 6 Artifact 的正确组 ID 和 Artifact ID 是什么?

java - 如何在 NetBeans IDE 中重命名我的主类?

java - 使用 servlet 在服务器端验证单选按钮

Java ftp4j - 以 amn 主动模式连接时列出 FTP 服务器中的文件

java - 从 Java Servlet 发送巨大的 json 对象