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/