[英]Deployment on Wildfly: ClassNotFoundException: Oracle12cDialect
[英]BouncyCastle ClassNotFoundException on deployment to WildFly
我想使用BouncyCastle API(v 1.52)在WildFly服务器上的Web应用程序中使用PBKDF2WithHmacSHA1-alogrithm对密码进行哈希处理。 但是,总是在部署应用程序时从服务器获取“ ClassNotFoundException org.bouncycastle.crypto.PBEParametersGenerator”。 我正在使用Eclipse Mars和WildFly 8.2.0和9.0.1。 我在Eclipse中的项目中没有任何错误。 我已经尝试按照此处另一个主题中的描述,将BouncyCastle JAR添加到我的类路径中,但这没有帮助。 我想知道为什么我在这里或Google上找不到关于此问题的任何其他结果,有人可以帮助我吗? 我知道Java 8具有PBKDF2WithHmacSHA256实现,但是我仍然想使用BouncyCastle API作为替代。
这是一个产生上述错误的项目的非常简单的示例:
BouncyCastleHasher.java:
import java.util.Arrays;
import java.util.Base64;
import javax.faces.bean.ManagedBean;
import org.bouncycastle.crypto.PBEParametersGenerator;
import org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator;
import org.bouncycastle.crypto.params.KeyParameter;
@ManagedBean
public class BouncyCastleHasher {
private String input;
private String output;
public String hash() {
if(input!=null) {
byte[] salt = "12345678".getBytes();
PBEParametersGenerator generator = new PKCS5S2ParametersGenerator();
generator.init(PBEParametersGenerator.PKCS5PasswordToUTF8Bytes(input.toCharArray()), salt, 1);
KeyParameter params = (KeyParameter)generator.generateDerivedParameters(128);
byte[] hash = Arrays.toString(params.getKey()).getBytes();
String encodedText = Base64.getEncoder().encodeToString(hash);
setOutput(encodedText);
}
return "out";
}
public String getInput() {
return input;
}
public void setInput(String input) {
this.input = input;
}
public String getOutput() {
return output;
}
public void setOutput(String output) {
this.output = output;
}
}
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>Test_BouncyCastle</display-name>
<welcome-file-list>
<welcome-file>in.xhtml</welcome-file>
</welcome-file-list>
</web-app>
in.xhtml:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:a="http://xmlns.jcp.org/jsf/passthrough"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Hashing site</title>
</h:head>
<h:body>
<h:form>
<table>
<tr>
<td>
<h:outputText value="Text to hash:" />
</td>
<td>
<h:inputText value="#{bouncyCastleHasher.input}" ></h:inputText>
</td>
</tr>
<tr>
<td>
<h:commandButton value="Save"
action="#{bouncyCastleHasher.hash}"></h:commandButton>
</td>
</tr>
</table>
</h:form>
</h:body>
</html>
out.xhtml:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:a="http://xmlns.jcp.org/jsf/passthrough"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Result</title>
</h:head>
<h:body>
<h:form>
<table>
<tr>
<td>
<h:outputText value="hashed text:" />
</td>
<td>
<h:outputText value="#{bouncyCastleHasher.output}"></h:outputText>
</td>
</tr>
</table>
</h:form>
<h:link outcome="in"/>
</h:body>
</html>
BouncyCastle库作为JBoss模块包含在WildFly发行版中。
请尝试将org.bouncycastle
模块导入您的应用程序,并确保WAR中不包含BouncyCastle库的副本,例如,通过为POM中的BouncyCastle依赖项使用provided
范围。
有关导入模块的更多详细信息,请参见WildFly中的类加载 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.