Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void run()
- {
- while (true)
- {
- try
- {
- System.out.println("Podaj do kogo chcesz napisac: ");
- String adresat=br.readLine();
- String host = serwer.dajHost(adresat);
- Key klucz = serwer.dajKlucz(adresat);
- int port = serwer.dajPort(adresat);
- if (host!=null)
- {
- gniazdko = new Socket(host,port);
- Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
- cipher.init(Cipher.ENCRYPT_MODE,klucz);
- //out = new ObjectOutputStream((gniazdko.getOutputStream()));
- out = new ObjectOutputStream(gniazdko.getOutputStream());
- System.out.println(out.toString());
- System.out.println("Udalo sie podlaczyc z: "+adresat+". Podaj tresc wiadomosci: ");
- String line = br.readLine();
- ByteArrayOutputStream BAOS = new ByteArrayOutputStream();
- CipherOutputStream COS = new CipherOutputStream(BAOS, cipher);
- COS.write(line.getBytes());
- byte [] B = BAOS.toByteArray();
- System.out.println(new String(B));
- paczka wiadomosc = new paczka(nazwa,adresat,line);
- out.writeObject(B);
- out.flush();
- out.close();
- }
- else
- {
- System.out.println("Nie ma takiego kogos");
- }
- }
- catch (Exception e)
- {
- System.out.println(e.toString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement