Browse Source

Broken code, need to figure out flushing

crypto
Thomas Johnson 3 years ago
parent
commit
bf68ba54c2
  1. 3
      crypto/CryptoSocket.java
  2. 54
      sample/Main.java

3
crypto/CryptoSocket.java

@ -58,7 +58,8 @@ public class CryptoSocket
this.key = new SecretKeySpec(keybytes, "AES");
try {
this.ciphout = Cipher.getInstance("AES/OFB/PKCS5Padding");
this.ciphout = Cipher.getInstance("AES/CBC/PCKS5Padding");
this.ciphin = Cipher.getInstance("AES/CBC/PKCS5Padding");
} catch (NoSuchAlgorithmException e) {
throw new IOException("NoSuchAlgorithmException: " + e.getMessage());
} catch (NoSuchPaddingException e) {

54
sample/Main.java

@ -1,23 +1,53 @@
package sample;
import crypto.CryptoSocket;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
import javax.xml.crypto.Data;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
public class Main
{
public static void main(String[] args) {
launch(args);
}
try
{
ServerSocket sock = new ServerSocket(25519);
Socket s = new Socket("127.0.0.1", 25519);
System.out.println("launching other thread");
new Thread(new Runnable() { public void run() { try
{
CryptoSocket csock = new CryptoSocket(sock.accept());
DataOutputStream out = csock.getOutputStream();
DataInputStream in = csock.getInputStream();
out.writeUTF("server->client");
out.flush();
synchronized (System.out)
{
System.out.print("server: ");
System.out.println(in.readUTF());
}
} catch (Exception e) {} } }).start();
System.out.println("done; connecting socket");
CryptoSocket csock = new CryptoSocket(s);
DataOutputStream out = csock.getOutputStream();
DataInputStream in = csock.getInputStream();
out.writeUTF("client->server");
out.flush();
synchronized (System.out)
{
System.out.println("client: ");
System.out.println(in.readUTF());
}
System.out.println("done");
} catch (IOException e)
{
e.printStackTrace();
}
}
}
Loading…
Cancel
Save