Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Command
- public void startsecure() throws Exception {
- SecureRandom secureRandom = new SecureRandom();
- this.clientChallenge = new byte[32];
- secureRandom.nextBytes(this.clientChallenge);
- this.initVector = new byte[16];
- secureRandom.nextBytes(this.initVector);
- KeyGenerator generator = KeyGenerator.getInstance("AES");
- generator.init(256); // KEYSIZE is in bits
- this.secretKey = generator.generateKey();
- try {
- //establish connection
- mailboxWriter.println("startsecure\r");
- mailboxWriter.flush();// 1
- String[] response = mailbodxReader.readLine().split(" "); // ok <component-id>
- if (!response[0].equals("ok")) {
- //throw exception here
- }
- this.publicServerKey = Keys.readPublicKey(new File("./keys/client/" + response[1] + ".pub"));
- String challengeBase64 = new String(Base64.encodeMessage(clientChallenge), StandardCharsets.UTF_8);
- String initVectorBase64 = new String(Base64.encodeMessage(initVector), StandardCharsets.UTF_8);
- String secretKeyBase64 = new String(Base64.encodeMessage(secretKey.getEncoded()), StandardCharsets.UTF_8);
- String msg = "ok " + challengeBase64 + " " + initVectorBase64 + " " + secretKeyBase64;
- System.out.println(msg + " " + Base64.decodeMessage(challengeBase64.getBytes()) + " " + msg.getBytes());
- byte[] b = msg.getBytes(Charset.forName("UTF-8"));
- String serverMessage = new String(RSAMethod.encodeMessage(publicServerKey,b), StandardCharsets.UTF_8);
- mailboxWriter.println("Test" + serverMessage + "\r"); // 3
- mailboxWriter.flush();
- // mailboxWriter.println("login" + this.mailboxUser + " " + mailboxPassword +"\r");
- } catch (IOException e) {
- e.printStackTrace();
- }
- //login
- }
Advertisement
Add Comment
Please, Sign In to add comment