· 9 years ago · Apr 01, 2017, 06:24 PM
1---------------------------------------------CA--------------------------------------------------------------
2 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
3 // TODO add your handling code here
4 Revocation r=new Revocation();
5 r.setVisible(true);
6
7 }//GEN-LAST:event_jButton1ActionPerformed
8
9 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
10 // TODO add your handling code here:
11 CAaccept ca=new CAaccept();
12 ca.setVisible(true);
13 }//GEN-LAST:event_jButton2ActionPerformed
14----------------------------------------------CA ACCEPT------------------------------------------------------------
15 public CAaccept() {
16 initComponents();
17 this.getContentPane().setBackground(Color.green);
18 this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
19 this.setTitle("Central_Authority");
20 this.setResizable(false);
21 try {
22 Class.forName("com.mysql.jdbc.Driver");
23
24 Connection connection = database.getConnection( );
25 Statement stmt = connection.createStatement();
26 ResultSet rs = stmt.executeQuery("select unm from keysignup" );
27 while(rs.next()){
28 jComboBox1.addItem(rs.getString(1));
29 }
30 }catch(Exception e){
31 e.printStackTrace();
32 }
33 }
34-----------------------------------------------CA LOGIN-----------------------------------------------------------
35private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
36 // TODO add your handling code here:
37 if(jTextField1.getText().equals("CA") && jPasswordField1.getText().equals("CA") )
38 {
39 CA c=new CA();
40 c.setVisible(true);
41 dispose();
42 }
43 else{
44 JOptionPane.showMessageDialog(null,"Incorrect either Username or Password","ERROR",JOptionPane.ERROR_MESSAGE);
45 }
46 }//GEN-LAST:event_jButton1ActionPerformed
47--------------------------------------------DATABASE.java----------------------------------------------
48public class database {
49 static Connection con=null;
50 public static Connection getConnection() throws Exception{
51 Class.forName("com.mysql.jdbc.Driver");
52 con=DriverManager.getConnection("jdbc:mysql://localhost:3306/CP-ABE","root","root");
53
54 return con;
55 }
56-----------------------------------------DECRYPT DATA-------------------------------------------------
57try{
58 Connection con1=database.getConnection();
59
60 Statement st1=con1.createStatement();
61 ResultSet r1=st1.executeQuery("select AES_DECRYPT(fdata,'"+skey+"')from storenode where fname='"+fnm+"'");
62
63 while(r1.next())
64 {
65 b=r1.getBytes(1);
66 }
67 String data=new String(b);
68 jTextArea1.append(data);
69 }catch(NullPointerException e){
70 JOptionPane.showMessageDialog(null,
71 "Please Enter Valid Secret-Key",
72 "Error",
73 JOptionPane.ERROR_MESSAGE);
74 }catch(Exception e){
75 e.printStackTrace();
76 }
77 }
78---------------------------------------------ENCRYPT DATA----------------------------------------
79 try{
80 this.fname=f4;
81 Connection con=database.getConnection();
82 PreparedStatement pst=con.prepareStatement("select fdata from storenode where fname='"+f4+"'");
83
84
85 ResultSet r=pst.executeQuery();
86 while(r.next()){
87
88 b=r.getBytes(1);
89 }
90 String data=new String(b);
91 //System.out.println(data);
92 jTextArea1.append(data);
93 //dispose();
94 }catch(Exception e){
95 e.printStackTrace();
96
97 }
98---------------------------------------------FILES DATA----------------------------------------------------
99 try {
100 Class.forName("com.mysql.jdbc.Driver");
101
102 Connection connection = DriverManager.getConnection( url, userid, password );
103 Statement stmt = connection.createStatement();
104 ResultSet rs = stmt.executeQuery( sql );
105
106 ResultSetMetaData md = rs.getMetaData();
107 int columns = md.getColumnCount();
108
109 // Get column names
110 for (int i = 1; i <= columns; i++)
111 {
112 columnNames.add( md.getColumnName(i) );
113 }
114
115 // Get row data
116 while (rs.next())
117 {
118 ArrayList row = new ArrayList(columns);
119
120 for (int i = 1; i <= columns; i++)
121 {
122 row.add( rs.getObject(i) );
123 }
124
125 data.add( row );
126 }
127 }
128 catch (Exception e)
129 {
130 System.out.println( e.getMessage() );
131 }
132--------------------------------------------------------HOME NUVVE SELECT CHESI PETTU, I CAN'T DECIDE---------------------------
133/*
134 * To change this template, choose Tools | Templates
135 * and open the template in the editor.
136 */
137package ABE;
138
139import java.awt.Color;
140
141/**
142 *
143 * @author ali
144 */
145public class Home extends javax.swing.JFrame {
146
147 /**
148 * Creates new form Home
149 */
150 public Home() {
151 initComponents();
152 this.getContentPane().setBackground(Color.ORANGE);
153 }
154
155 /**
156 * This method is called from within the constructor to initialize the form.
157 * WARNING: Do NOT modify this code. The content of this method is always
158 * regenerated by the Form Editor.
159 */
160 @SuppressWarnings("unchecked")
161 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
162 private void initComponents() {
163
164 jButton1 = new javax.swing.JButton();
165 jButton2 = new javax.swing.JButton();
166 jButton3 = new javax.swing.JButton();
167 jLabel3 = new javax.swing.JLabel();
168
169 setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
170 setForeground(new java.awt.Color(0, 51, 255));
171 getContentPane().setLayout(new java.awt.GridBagLayout());
172
173 jButton1.setText("Sender");
174 getContentPane().add(jButton1, new java.awt.GridBagConstraints());
175
176 jButton2.setText("Users");
177 getContentPane().add(jButton2, new java.awt.GridBagConstraints());
178
179 jButton3.setText("Key authorities");
180 getContentPane().add(jButton3, new java.awt.GridBagConstraints());
181
182 jLabel3.setBackground(new java.awt.Color(51, 51, 0));
183 jLabel3.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
184 jLabel3.setForeground(new java.awt.Color(0, 102, 0));
185 jLabel3.setText("Secure Data Retrieval for Decentralized Disruption-Tolerant Military Networks");
186 getContentPane().add(jLabel3, new java.awt.GridBagConstraints());
187
188 pack();
189 }// </editor-fold>//GEN-END:initComponents
190
191 /**
192 * @param args the command line arguments
193 */
194 public static void main(String args[]) {
195 /* Set the Nimbus look and feel */
196 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
197 /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
198 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
199 */
200 try {
201 for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
202 if ("Nimbus".equals(info.getName())) {
203 javax.swing.UIManager.setLookAndFeel(info.getClassName());
204 break;
205 }
206 }
207 } catch (ClassNotFoundException ex) {
208 java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
209 } catch (InstantiationException ex) {
210 java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
211 } catch (IllegalAccessException ex) {
212 java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
213 } catch (javax.swing.UnsupportedLookAndFeelException ex) {
214 java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
215 }
216 //</editor-fold>
217
218 /* Create and display the form */
219 java.awt.EventQueue.invokeLater(new Runnable() {
220 public void run() {
221 new Home().setVisible(true);
222 }
223 });
224 }
225 // Variables declaration - do not modify//GEN-BEGIN:variables
226 private javax.swing.JButton jButton1;
227 private javax.swing.JButton jButton2;
228 private javax.swing.JButton jButton3;
229 private javax.swing.JLabel jLabel3;
230 // End of variables declaration//GEN-END:variables
231}
232-------------------------------------------------KEY AUTHOR HOME---------------------------------------
233 try{
234 Connection con=database.getConnection();
235 Statement st=con.createStatement();
236 Statement st1=con.createStatement();
237 ResultSet r=st.executeQuery("select batalion from keysignup where unm='"+unm+"'");
238 if(r.next()){
239 batalion=r.getString(1);
240
241 }
242
243 }catch(Exception e){
244 e.printStackTrace();
245 }
246 UserDetails frame=new UserDetails(unm,batalion);
247
248 frame.pack();
249 frame.setVisible(true);
250
251 }//GEN-LAST:event_jButton1ActionPerformed
252------------------------------------------------KEY AUTHOR LOGIN-----------------------------------------
253 try{
254 Connection con=database.getConnection();
255 Statement st=con.createStatement();
256 Statement st1=con.createStatement();
257 ResultSet r=st.executeQuery("select *from keysignup where unm='"+unm+"' and pwd='"+pwd+"'");
258 if(r.next())
259 {
260 ResultSet r1=st.executeQuery("select *from keysignup where unm='"+unm+"' and status='Not-Accepted'");
261 if(r1.next())
262 {
263 JOptionPane.showMessageDialog(null,"Your Request is Under the Process...");
264 }
265 else{
266 KeyAuthorHome kah=new KeyAuthorHome(unm);
267 kah.setVisible(true);
268 dispose();
269 }
270 }else{
271 JOptionPane.showMessageDialog(null,"Incorrect Either Username or Password", "Error",JOptionPane.ERROR_MESSAGE);
272
273}
274 }catch(Exception e){
275 e.printStackTrace();
276 }
277 }//GEN-LAST:event_jButton1ActionPerformed
278------------------------------------------------KEY AUTHOR REG-------------------------------------------------
279 try{
280 Connection con=database.getConnection();
281 PreparedStatement pst=con.prepareStatement("insert into keysignup values(?,?,?,?,?)");
282 pst.setString(1,unm);
283 pst.setString(2,pwd);
284 pst.setString(3,eid);
285 pst.setString(4,b);
286 pst.setString(5,"Not-Accepted");
287
288 int i=pst.executeUpdate();
289 if(i==1){
290 JOptionPane.showMessageDialog(null,"Key-Authority Registerd Successfully");
291 }
292 dispose();
293 }catch(Exception e){
294 e.printStackTrace();
295 }
296------------------------------------------------MAIN.JAVA----------------------------------------------------
297 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
298 // TODO add your handling code here:
299 Sender s=new Sender();
300 s.setVisible(true);
301
302 }//GEN-LAST:event_jButton1ActionPerformed
303
304 private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
305 // TODO add your handling code here:
306 KeyAuthorLogin kl=new KeyAuthorLogin();
307 kl.setVisible(true);
308 }//GEN-LAST:event_jButton3ActionPerformed
309
310 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
311 // TODO add your handling code here:
312 User_Login ul=new User_Login();
313 ul.setVisible(true);
314 }//GEN-LAST:event_jButton2ActionPerformed
315--------------------------------------------REQUESTED KEY--------------------------------------------------
316 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
317 // TODO add your handling code here
318 String unm= jComboBox1.getSelectedItem().toString();
319 String ka= jComboBox2.getSelectedItem().toString();
320 String batalion= jComboBox3.getSelectedItem().toString();
321 try{
322 Connection con=database.getConnection();
323 Statement st=con.createStatement();
324 st.executeUpdate("delete from requested");
325 PreparedStatement pst=con.prepareStatement("insert into requested values(?,?,?)");
326 pst.setString(1,unm);
327 pst.setString(2,ka);
328 pst.setString(3,batalion);
329
330 int i=pst.executeUpdate();
331 if(i==1){
332 JOptionPane.showMessageDialog(null,"Request Sent to Key-Authority Successfully");
333 }
334 dispose();
335 }catch(Exception e){
336 e.printStackTrace();
337
338 }
339
340 }
341-------------------------------------------------REVOCATION---------------------------------------------
342 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
343 // TODO add your handling code here:
344 try {
345
346
347
348 Connection connection = database.getConnection( );
349 Statement stmt = connection.createStatement();
350 int i= stmt.executeUpdate("Update signup set status='Revoked' where unm ='"+jComboBox1.getSelectedItem()+"'" );
351 if(i>=1)
352 {
353 JOptionPane.showMessageDialog(null,"User"+" "+" ' "+jComboBox1.getSelectedItem()+" ' "+" "+"is Revoked");
354
355 }
356 }catch(Exception e){
357 e.printStackTrace();
358 }
359
360 }
361--------------------------------------------------SENDER.JAVA-------------------------------------------------
362 private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
363 // TODO add your handling code here:
364 try{
365 Connection con=database.getConnection();
366 PreparedStatement pst=con.prepareStatement("select *from key_");
367
368 ResultSet r=pst.executeQuery();
369 if(r.next()){
370 System.out.println(r.getString(1));
371 jPasswordField1.setText(r.getString(1));
372 }
373 // dispose();
374 }catch(Exception e){
375 e.printStackTrace();
376 }
377
378 }//GEN-LAST:event_jButton3ActionPerformed
379-------------------------------------------------SEND KEY----------------------------------------------
380public class SendKey {
381 String key1;
382 public void setKey(String key){
383
384 this.key1=key;
385 System.out.println("key="+key1);
386 }
387 public String getKey(){
388
389 return this.key1;
390 }
391}
392--------------------------------------------STORAGE NODE---------------------------------------------------
393 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
394 // TODO add your handling code here:
395 FilesDetails f=new FilesDetails();
396 f.pack();
397 f.setVisible(true);
398
399 }//GEN-LAST:event_jButton1ActionPerformed
400---------------------------------------------USER HOME-------------------------------------------------------
401 try{
402 Connection con1=database.getConnection();
403
404 Statement st1=con1.createStatement();
405 Statement st2=con1.createStatement();
406 ResultSet r2=st2.executeQuery("select access from signup where unm='"+unm+"'");
407
408 if(r2.next()){
409 aces=r2.getString(1);
410
411 }
412
413 Statement s3=con1.createStatement();
414 ResultSet rs4=s3.executeQuery("select *from signup where unm='"+unm+"' and status='Revoked'");
415 if(!(rs4.next()))
416 {
417
418
419 Statement st3=con1.createStatement();
420 ResultSet r4=st3.executeQuery("select *from storenode where fname='"+fname+"' and access='"+aces+"'");
421 if(r4.next())
422 {
423 ResultSet r3=st1.executeQuery("select fdata from storenode where fname='"+fname+"'");
424
425 while(r3.next())
426 {
427
428 b=r3.getBytes(1);
429 }
430 String data=new String(b);
431 jTextArea1.setText("");
432 jTextArea1.append(data);
433
434 }
435 else{
436 JOptionPane.showMessageDialog(null,"You Can not Access this File","Warning",JOptionPane.WARNING_MESSAGE);
437 }
438 }
439 else{
440 JOptionPane.showMessageDialog(null,"Your Revoked and You Can not Access this File","Warning",JOptionPane.WARNING_MESSAGE);
441
442 }
443 }catch(Exception e){
444 e.printStackTrace();
445 }
446---------------------------------------------------USER LOGIN-----------------------------------------------
447private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
448 // TODO add your handling code here:
449 String unm=jTextField1.getText();
450 String pwd=jPasswordField1.getText();
451 try{
452 Connection con=database.getConnection();
453 Statement st=con.createStatement();
454 Statement st1=con.createStatement();
455 ResultSet r=st.executeQuery("select *from signup where unm='"+unm+"' and pwd='"+pwd+"'");
456 if(r.next())
457 {
458 User_Home uhm=new User_Home(unm);
459 uhm.setVisible(true);
460 dispose();
461 }
462 else{
463 JOptionPane.showMessageDialog(null,"Incorrect either Username or Password","Error",JOptionPane.ERROR_MESSAGE);
464 }
465 }catch(Exception e){
466 e.printStackTrace();
467 }
468 }//GEN-LAST:event_jButton1ActionPerformed
469-------------------------------------------------USER_REG------------------------------------------------
470 java.awt.EventQueue.invokeLater(new Runnable() {
471 public void run() {
472 new User_Reg().setVisible(true);
473 }
474 });
475-----------------------------------------------UserDetails-------------------------------------------------------
476 // Get column names
477 for (int i = 1; i <= columns; i++)
478 {
479 columnNames.add( md.getColumnName(i) );
480 }
481
482 // Get row data
483 while (rs.next())
484 {
485 ArrayList row = new ArrayList(columns);
486
487 for (int i = 1; i <= columns; i++)
488 {
489 row.add( rs.getObject(i) );
490 }
491
492 data.add( row );
493 }
494--------------------------------------------------------------------------------------------------------------------
495---------------------------------------------------xXx--------------------------------------------------------------