我寫了一個簡單的JSP LOGIN頁面。我以加密格式收到密碼。我正在解密它。所以只是爲了試一試我正在加密一個示例字符串,所以它需要將字節數組編碼爲十六進制字符串,我正在嘗試在我的代碼的最後一個語句中執行此操作。將字節數組轉換爲十六進制十進制字符串
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.security.*" %>
<%@ page import="javax.crypto.*" %>
<%@ page import="javax.crypto.spec.*" %>
<%@ page import="java.lang.*" %>
<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","xxxxxx","xxxxxx");
// @//machineName:port:SID, userid, password
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("Select * from Cxxxxxxx");
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("UTF-8"), algorithm1);
cipher = Cipher.getInstance(algorithm2);
String str="test4abc";
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);
//Problem is in the statement BELOW --->
String encoded = new String(Hex.encodeHex(encrypted));
}
%>
</BODY>
</HTML>
錯誤我收到的是:
[jsp src:line #:48]
cannot resolve symbol symbol : variable Hex location: class _check1 String encoded = new String(Hex.encodeHex(encrypted));
我應該怎麼做這個聲明運行或任何其他可替代
等等,你爲什麼說「org.apache.commons.codec.binary.Hex是java.lang。」?類'Hex'在'org.apache.commons.codec.binary'包中,而不是'java.lang'包中。 – 2012-07-10 04:49:59
那麼如何在JSP中包含這個包? – Murtaza 2012-07-10 04:57:04