我是Oracle和JSP的新手。作为我工作的一部分,我尝试在JSP中创建一个登录页面。所以我已经将其连接到数据库,并且我拥有所有用户名和密码。但是passowrd是加密格式的。。我的主管告诉我,它已在dbms_obfuscation_toolkit.DESEncrypt中加密。我必须将该密码解密为原始密码,以便可以使用登录页面上提供的密码进行检查。。我在JSP中使用此代码:
<%@ page import="java.sql.*" %> <%@ page import="java.security.*" %> <%@ page import="javax.crypto.*" %> <%@ page import="javax.crypto.spec.*" %> <HTML> <HEAD> <TITLE>Simple JSP/Oracle Query Example</TITLE> </HEAD> <BODY> <% Class.forName("oracle.jdbc.OracleDriver"); Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@xxx:xxxx:xxxx","ixxxer","ixxxer"); // @//machineName:port:SID, userid, password Statement st=conn.createStatement(); ResultSet rs=st.executeQuery("Select * from Cusxxxxer"); while(rs.next()){ String name=rs.getString("user_id"); String p=rs.getString("password"); out.println(name+":"+p); out.println("</br>"); String algorithm1 = "DES";//magical mystery constant String algorithm2 = "DES/CBC/NoPadding";//magical mystery constant IvParameterSpec iv = new IvParameterSpec( new byte [] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } );//magical mystery constant Cipher cipher; SecretKey key; String k="12345abc"; key = new SecretKeySpec( k.getBytes( ), algorithm1 ); cipher = Cipher.getInstance( algorithm2 ); String str="test1234abc"; cipher.init( Cipher.ENCRYPT_MODE, key, iv ); //normally you could leave out the IvParameterSpec argument, but not with Oracle byte[] bytes=str.getBytes("UTF-8"); byte[] encrypted = cipher.doFinal( bytes ); } %> </BODY> </HTML>
我对语句的最后一行有疑问:byte[] encrypted = cipher.doFinal( bytes );该语句给我一个错误:
byte[] encrypted = cipher.doFinal( bytes );
javax.crypto.IllegalBlockSizeException:输入长度不是com.sun.crypto.provider.SunJCE_h.b(DashoA6275)处com.sun.crypto.provider.SunJCE_h.a(DashoA6275)处的8个字节的倍数。 com.sun.crypto.provider.DESCipher.engineDoFinal(DashoA6275)上的provider.SunJCE_h.b(DashoA6275)_check1._jspService(_check1.java:83)处javax.crypto.Cipher.doFinal(DashoA6275)的provider .jsp:45],位于com.orionserver [Oracle J2EE应用服务器容器10g(10.1.2.0.2)]。http.OrionHttpJspPage.service(OrionHttpJspPage.java:56),位于oracle.jsp.runtimev2.JspPageTable.service(JspPageTable .java:350)位于oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:509)位于oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:413)位于javax.servlet.http.HttpServlet.service( HttpServlet.java:853)。evermind [J2EE 10g的Oracle应用服务器容器(10.1.2.0.2)]。server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:824)at com.evermind [J2EE的Oracle应用服务器容器(10.1.2.0.2) )]。server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:330),位于com.evermind [用于J2EE 10g的Oracle应用服务器容器(10.1.2.0.2)]。server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java: 830)at com.evermind [J2EE 10g的Oracle应用服务器容器(10.1.2.0.2)]。server.http.HttpRequestHandler.run(HttpRequestHandler.java:285)at com.evermind [J2EE 10g的Oracle应用服务器容器( 10.1.2.0.2)]。server.http.HttpRequestHandler.run(HttpRequestHandler.java:126)at com.evermind [用于J2EE 10g的Oracle应用服务器容器(10.1.2.0.2)]。util。ReleasableResourcePooledExecutor $ MyWorker.run(ReleasableResourcePooledExecutor.java:186)在java.lang.Thread.run(Thread.java:534)
我知道错误意味着参数需要8字节的倍数。但是我该怎么办?请任何人都可以更正我的代码或给我其他示例。我是JSP和ORACLE的新手,所以他们不太了解。提前致谢!:)
请更换
String str="test1234abc";
至
String str="12345abc";