· 6 years ago · Jun 13, 2019, 01:16 PM
1<%@ page language="java" contentType="text/html" %>
2<%@page import="java.sql.*,java.util.*" %>
3<%@page import="java.io.*"%>
4<%@page import="java.io.IOException"%>
5<%@page import="java.io.UnsupportedEncodingException"%>
6<%@page import="java.security.InvalidAlgorithmParameterException"%>
7<%@page import="java.security.InvalidKeyException"%>
8<%@page import="java.security.NoSuchAlgorithmException"%>
9<%@page import="java.security.spec.AlgorithmParameterSpec"%>
10<%@page import="java.security.spec.InvalidKeySpecException"%>
11<%@page import="java.security.spec.KeySpec"%>
12<%@page import="java.security.spec.KeySpec"%>
13<%@page import="java.security.*"%>
14<%@page import="javax.crypto.*"%>
15<%@page import="javax.crypto.spec.PBEKeySpec"%>
16<%@page import="javax.crypto.spec.PBEParameterSpec"%>
17<%@page import="java.util.Base64"%>
18 <%
19 String op = request.getParameter("op");
20 String saltID = (String)request.getAttribute("csrfPreventionSalt");
21 String key = "ezeon8547";
22 String enc = encrypt(key, saltID);
23 System.out.println("Encrypted text: "+enc);
24 if(saltID != null)
25 {
26 session.setAttribute("crsf", saltID);
27 }
28 if(op==null) { //out.println(">>>>>>>>>>>>"+session.getAttribute("REGISTRATION_ERROR"));
29 session.removeAttribute("registerBean");
30 session.removeAttribute("REGISTRATION_ERROR");
31 //session.invalidate();
32 }
33%>
34<%
35 if(session.getAttribute("REGISTRATION_ERROR")!=null) {
36
37 }
38 try {
39 if(true) {
40 String address = "my address"
41 String state = "my state";
42 String city = "my city";
43 String pincode = "500100";
44%>
45<table align="left" border="0" width="80%">
46<tr>
47 <td></td> <!-- For right space -->
48 <!-- Data Table STart Below -->
49 <td>
50 <table width="100%" cellpadding="0" cellspacing="0">
51 <tr><td width="100%">
52 <div class="frmtbldata">
53 <table width="100%" cellpadding="4" cellspacing="1" style="font-size: 1.1em">
54 <tr>
55 <th height="20" class="centr" colspan="2" valign="top">Edit Address
56 </th>
57 </tr>
58 <tr>
59 <th width="40%" >Enter your existing address</th>
60 <td ><input type="text" name="addressOld" id="addressOld" value="<%=address%>" readonly class="reporttitle1"></input>
61 </td>
62 </tr>
63 <tr>
64 <th width="40%" > <font class="contenttext">Enter your existing city</td>
65 <td class="t0"><input type="text" name="cityOld" id="cityOld" value="<%=city%>" readonly class="reporttitle1"></input>
66 </td>
67 </tr>
68 <tr>
69 <th width="40%" >Enter your existing state</th>
70 <td ><input type="text" name="stateOld" id="stateOld" value="<%=state%>" readonly class="reporttitle1"></input>
71 </td>
72 </tr>
73 <tr>
74 <th width="40%" >Enter your existing pincode</th>
75 <td ><input type="text" name="pincodeOld" id="pincodeOld" value="<%=pincode%>" readonly class="reporttitle1"></input>
76 </td>
77 </tr>
78 <tr>
79 <th width="40%">Enter your new address</th>
80 <td ><input type="text" name="addressNew" id="addressNew" value="" class="reporttitle1"></input>
81 </td>
82 </tr>
83 <tr>
84 <th width="40%">Enter your new city</th>
85 <td><input type="text" name="cityNew" id="cityNew" value="" class="reporttitle1"></input>
86 </td>
87 </tr>
88 <tr>
89 <th width="40%" >Enter your new state</font></th>
90 <td class="t0"><input type="text" name="stateNew" id="stateNew" value="" class="reporttitle1"></input>
91 </td>
92 </tr>
93 <tr>
94 <th width="40%">Enter your new pincode</td>
95 <td ><input type="text" name="pincodeNew" id="pincodeNew" value="<%= saltID %>" maxlength="6" class="reporttitle1"></input>
96 </td>
97 </tr>
98 <td ><input type="text" name="saltToken" id="saltToken" value="<%= saltID %>"></input>
99 </td>
100 <!--<td ><input type="hidden" name="crsf" id="crsf" value="<%= saltID %>"></input> -->
101 </td>
102 <th height="30" class="centr" colspan="2">
103 <input type="button" value="Submit" id="Submit" onClick="validateAddress('/registration/tv/trades/newStructure/editModule/editAddressConfirm.jsp?module=A&Token=<%= saltID %>')">
104 <img src="/images/trans.gif" width="80" height="1">
105 <!--<input type="reset" name ="reset" value="Clear" > -->
106 </th>
107 </tr>
108 </table>
109 </div>
110 </td></tr>
111 </table>
112 </td>
113 <!-- Data Table end -->
114 <td></td><!-- For left space -->
115</tr>
116</table>
117<%}else{
118System.out.println("Invalid user in edit address >>>>>>>>>>>>");
119}
120}catch(Exception e){
121System.out.println("Invalid user in edit address >>>>>>>>>>>>.Please try later");
122}
123%>
124<%!
125 public String encrypt(String secretKey, String plainText)
126 throws NoSuchAlgorithmException,
127 InvalidKeySpecException,
128 NoSuchPaddingException,
129 InvalidKeyException,
130 InvalidAlgorithmParameterException,
131 UnsupportedEncodingException,
132 IllegalBlockSizeException,
133 BadPaddingException,
134 Exception
135 {
136 Cipher ecipher;
137 // 8-byte Salt
138 byte[] salt = {(byte) 0xA9, (byte) 0x9B, (byte) 0xC8, (byte) 0x32, (byte) 0x56, (byte) 0x35, (byte) 0xE3, (byte) 0x03};
139 // Iteration count
140 int iterationCount = 19;
141 //Key generation for enc and desc
142 KeySpec keySpec = new PBEKeySpec(secretKey.toCharArray(), salt, iterationCount);
143 SecretKey key = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec);
144 // Prepare the parameter to the ciphers
145 AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt, iterationCount);
146
147 //Enc process
148 ecipher = Cipher.getInstance(key.getAlgorithm());
149 ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
150 String charSet="UTF-8";
151 byte[] inP = plainText.getBytes(charSet);
152 byte[] outP = ecipher.doFinal(inP);
153 String encStr = Base64.getEncoder().encodeToString(outP);
154 return encStr;
155 }
156%>