异常: java.security.InvalidKeyException: Illegal key size

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_43174314/article/details/87872360

tomcat启动报异常: java.security.InvalidKeyException: Illegal key size
上网搜索原因后完美解决,下面附上方法:

异常原因:如果密钥大于128, 会抛出java.security.InvalidKeyException: Illegal key size 异常. 因为密钥长度是受限制的, java运行时环境读到的是受限的policy文件. 文件位于${java_home}/jre/lib/security, 这种限制是因为美国对软件出口的控制.
解决方案:去官方下载JCE无限制权限策略文件。

jdk 5: http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-java-plat-419418.html#jce_policy-1.5.0-oth-JPR

jdk6: http://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.html

JDK7的下载地址: http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html
JDK8的下载地址: http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html

下载后解压,可以看到local_policy.jar和US_export_policy.jar以及readme.txt
如果安装了JRE,将两个jar文件放到%JRE_HOME%\lib\security目录下覆盖原来的文件
如果安装了JDK,还要将两个jar文件也放到%JDK_HOME%\jre\lib\security目录下覆盖原来文件。
over,解决。

展开阅读全文

急急!异常java.security.InvalidKeyException:No installed provider supports this key

05-30

我的jsp页面:rn<%@ page contentType="text/html;charset=gb2312"%>rn<%@ page import="org.des.dmw.*" %>rn<%@ page import="org.des.factory.*" %>rn<%@ page import="java.security.*" %>rn<%@ page import="javax.crypto.*" %>rnrnrn Jiami.jsprnrnrnrnrn<%rn request.setCharacterEncoding("gb2312");rn%>rn<% rn String text = request.getParameter("plaintext");rn String key = request.getParameter("key");rn DesFactory.getDesEncryptInstance().getKey(key);rn String strEnc = DesFactory.getDesEncryptInstance().getEncString(text);rn%>rnrn rn rn rn rn 输出密文:rn <%=strEnc%>rn rn rn rn rn rn rn rn rnrnrnrnrnrnrnDES算法程序:rnpackage org.des.dmw;rnrnimport java.security.*;rnimport javax.crypto.*;rnrnpublic class DesEncrypt rnrn Key key ;rn public void getKey(String strKey)rn rn tryrn rn KeyGenerator generator = KeyGenerator.getInstance("DES") ;rn generator.init(new SecureRandom(strKey.getBytes()));rn this.key = generator.generateKey();rn generator = null;rn rn catch(Exception e)rn rn e.printStackTrace(); rn rn rn public String getEncString(String strMing)rn rn byte[] byteMi = null;rn byte[] byteMing = null;rn String strMi = "";rn tryrn rn return byte2hex(getEncCode(strMing.getBytes()));rn catch(Exception e)rn rn e.printStackTrace();rn rn finallyrn byteMing = null;rn byteMi = null;rn rn return strMi;rn rn rn public String getDesString(String strMi)rn rn byte[] byteMing = null;rn byte[] byteMi = null;rn String strMing = "";rn tryrn return new String(getDesCode(hex2byte(strMi.getBytes())));rn catch(Exception e)rn rn e.printStackTrace();rn finallyrn rn byteMing = null;rn byteMi = null;rn rn return strMing;rn rn private byte[] getEncCode(byte[] byteS)rn rn byte[] byteFina = null;rn Cipher cipher;rn tryrn cipher = Cipher.getInstance("DES");rn cipher.init(Cipher.ENCRYPT_MODE, key);rn byteFina = cipher.doFinal(byteS);rn catch(Exception e)rn rn e.printStackTrace();rn finallyrn rn cipher = null;rn rn return byteFina;rn rn private byte[] getDesCode(byte[] byteD)rn rn Cipher cipher;rn byte[] byteFina = null;rn tryrn cipher = Cipher.getInstance("DES");rn cipher.init(Cipher.DECRYPT_MODE, key);rn byteFina = cipher.doFinal(byteD);rn catch(Exception e)rn rn e.printStackTrace();rn finallyrn rn cipher = null;rn rn return byteFina;rn rn public static String byte2hex(byte[] b)rn rn //转成16进制字符串rn String hs = "";rn String stmp = "";rn for(int n=0;n 论坛

异常java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

05-11

严重: Servlet.service() for servlet jsp threw exceptionrnjava.lang.IndexOutOfBoundsException: Index: 0, Size: 0rn at java.util.ArrayList.RangeCheck(ArrayList.java:547)rn at java.util.ArrayList.remove(ArrayList.java:387)rn at com.opensymphony.xwork2.util.CompoundRoot.pop(CompoundRoot.java:36)rn at com.opensymphony.xwork2.ognl.OgnlValueStack.pop(OgnlValueStack.java:379)rn at org.apache.struts2.components.Bean.end(Bean.java:146)rn at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)rn at org.apache.jsp.list_jsp._jspx_meth_s_005fbean_005f2(list_jsp.java:238)rn at org.apache.jsp.list_jsp._jspService(list_jsp.java:120)rn at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)rn at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)rn at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)rn at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)rn at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)rn at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)rn at org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:154)rn at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)rn at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:361)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:265)rn at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:163)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:249)rn at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:148)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:93)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:128)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:104)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:148)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:128)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)rn at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:468)rn at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)rn at java.lang.Thread.run(Thread.java:619)rn 论坛

castor xml转javabean 异常Illegal Text data found as child of”

04-17

直接上代码,求大拿帮忙。rn需要转化的xml:rn[code=html]rnrn human not like mernrn[/code]rn转化后的实体类:rn[code=java]package com;rnpublic class PpInfo rn private XmlObejcts objects;rnrn[/code]rnrn[code=java]package com;rnrnpublic class XmlObejcts rn private String elementtype;rn private String code;rn private String objects;rnrn public XmlObejcts() rn rn rn public XmlObejcts(String elementtype, String code)rn this.elementtype = elementtype;rn this.code = code;rn rnrn[/code]rnrnmain方法:rn[code=java] public static void main(String[] args) throws Exception rn FileReader reader = new FileReader("src//pp.xml");rn PpInfo ppInfo = (PpInfo) Unmarshaller.unmarshal(PpInfo.class,reader);rn System.out.println("--");rn [/code]rnrn异常:rn[code=java]Exception in thread "main" org.exolab.castor.xml.MarshalException: Illegal Text data found as child of: objectsrn value: "human not like me"File: [not available]; line: 3; column: 71rn at org.exolab.castor.xml.Unmarshaller.convertSAXExceptionToMarshalException(Unmarshaller.java:761)rn at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:727)rn at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:616)rn at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:807)rn at com.Test.main(Test.java:9)rnCaused by: org.xml.sax.SAXException: Illegal Text data found as child of: objectsrn value: "human not like me"rn at org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:874)rn at org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:1159)rn at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601)rn at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782)rn at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2939)rn at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)rn at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)rn at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)rn at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)rn at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)rn at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)rn at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)rn at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:715)rn ... 3 morernCaused by: org.xml.sax.SAXException: Illegal Text data found as child of: objectsrn value: "human not like me"[/code] 论坛

没有更多推荐了,返回首页