Advertisement
Pedro_Rocha

Untitled

Oct 16th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. String query = "INSERT INTO Clients ( Name, Contact, Address, City, PostalCode, Country, CardNumber) VALUES ('Name', '1234567890', 'Address', 'City', '90123', 'Country', '1234-1234-1234-1234')";
  2.  
  3. try {
  4.  
  5.     ResultSet query_result = statement.executeQuery ( query );
  6.  
  7. } catch ( Exception error ) {
  8.  
  9.     System.err.printf ( error.getMessage ( ) );
  10.  
  11. }
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18. Signature sign = Signature.getInstance ( "SHA256withRSA" );
  19.  
  20. KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance ( "RSA" );
  21. keyPairGen.initialize ( 2048 );
  22. KeyPair pair = keyPairGen.generateKeyPair ( );
  23.  
  24. Cipher cipher = Cipher.getInstance ( "RSA/ECB/PKCS1Padding" );
  25. cipher.init ( Cipher.ENCRYPT_MODE, pair.getPublic ( ) );
  26.  
  27. byte [] input = "('Name', '1234567890', 'Address', 'City', '90123', 'Country', '1234-1234-1234-1234')".getBytes ( );
  28. cipher.update ( input );
  29.  
  30. byte [] cipherText = cipher.doFinal ( );
  31. String aux = ( cipherText, "UTF8" );
  32.  
  33. String query = "INSERT INTO Clients ( Name, Contact, Address, City, PostalCode, Country, CardNumber ) VALUES " + aux;
  34.  
  35. try {
  36.  
  37.     ResultSet query_result = statement.executeQuery ( query );
  38.  
  39. } catch ( Exception error ) {
  40.  
  41.     System.err.printf ( error.getMessage ( ) );
  42.  
  43. }
  44.  
  45. System.out.println (new String ( cipherText, "UTF8" ) );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement