Advertisement
Guest User

Untitled

a guest
May 28th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. public void run()
  2. {
  3. while (true)
  4. {
  5. try
  6. {
  7. System.out.println("Podaj do kogo chcesz napisac: ");
  8. String adresat=br.readLine();
  9. String host = serwer.dajHost(adresat);
  10. Key klucz = serwer.dajKlucz(adresat);
  11. int port = serwer.dajPort(adresat);
  12. if (host!=null)
  13. {
  14. gniazdko = new Socket(host,port);
  15. Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
  16. cipher.init(Cipher.ENCRYPT_MODE,klucz);
  17.  
  18. //out = new ObjectOutputStream((gniazdko.getOutputStream()));
  19. out = new ObjectOutputStream(gniazdko.getOutputStream());
  20. System.out.println(out.toString());
  21.  
  22. System.out.println("Udalo sie podlaczyc z: "+adresat+". Podaj tresc wiadomosci: ");
  23. String line = br.readLine();
  24. ByteArrayOutputStream BAOS = new ByteArrayOutputStream();
  25. CipherOutputStream COS = new CipherOutputStream(BAOS, cipher);
  26. COS.write(line.getBytes());
  27. byte [] B = BAOS.toByteArray();
  28. System.out.println(new String(B));
  29. paczka wiadomosc = new paczka(nazwa,adresat,line);
  30. out.writeObject(B);
  31.  
  32. out.flush();
  33. out.close();
  34. }
  35. else
  36. {
  37. System.out.println("Nie ma takiego kogos");
  38. }
  39. }
  40. catch (Exception e)
  41. {
  42. System.out.println(e.toString());
  43. }
  44.  
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement