jsp - Convert Byte Array to Hexa Decimal String -


I have written a simple JSP login page. I have received the password in encrypted format. I am decrypting it so just for a try, I am encrypting a sample string, so it is hexadecimal string, which I am trying to do in the last statement of my code to indicate the byte array Need to change in words

 . & Lt; % @ Page Import = "java.sql. *"% "% & Gt; & Lt;% @ Page Import = "java.io. *"% & gt; & Lt;% @ page import = "java.security. *"% & Gt; & Lt;% @ Page Import = "javax.crypto. *"% <% & Gt; & Lt;% @ Page Import = "javax.crypto.spec. *"% "% & Gt; & Lt;% @ page import = "java.lang. *"% & Gt; & Lt; Html & gt; & Lt; HEAD & gt; & Lt; TITLE & gt; Simple JSP / Oracle query example & lt; / TITLE & gt; & Lt; / HEAD> & Lt; Body & gt; & Lt;% Class.forName ("oracle.jdbc.OracleDriver"); Connection Conn = DriverManager.getConnection ("JDBC: Oracle: thin: @xxx: xxxx: xxxx", "xxxxxx", "xxxxxx"); // @ // MachineName: Port: SID, UserAd, Password Statement st = conn.createStatement (); ResultSet rs = st.executeQuery ("Choose from Cxxxxxxx *"); While (rsnext ()) {string name = rs.getString ("user_id"); String P = rs.getString ("password"); Out.println (name + ":" + P); Out.println ("& lt; / br>"); String algorithm1 = "des"; // Magical Mystery Continuous String Algorithm2 = "DES / CBC / NoPadding"; // Magical mystery continuously IvParameterSpec iv = new IvParameterSpec (new byte [] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}); // magical mystery constant cipher cipher; Secret key; String k = "12345abc"; Key = new secretive speak (katt bits ("UTF-8"), algorithm 1); Cipher = cipher Get Instances (Algorithm 2); String str = "test4abc"; Cipher.init (cipher NCRYPMODEG, key, iv); // Normally you can leave the IvParameterSpec logic out, but not with Oracle byte [] bytes = str.getBytes ("UTF-8"); Byte [] Encrypted = Cipher Final (bytes); // problem is in the statement below ---> String encoded = new string (hex. Encodehex (encrypted)); }% & Gt; & Lt; / Body & gt; & Lt; / Html & gt;   

The error I am getting is that:

  [jsp src: line # 48] can not resolve the symbol symbol: variable hex location: Square _check1 string encoded = new string (hex. Encodehex (encrypted));   

I should run this statement to encode byteearray for hexadecimal string or make any other option

When I was working with JSP, I had to face a similar problem some time back. Error

  org.apache.commons.codec.binary 1.5 binary   

is solved and downloaded to Lib folder. Since then, access to that function:

  org.apache.commons.codec.binary.Hex.encodeHex (encrypted))   

This solves your problem should do.

Cheers!

Comments