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){
}
答案 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