Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- else if(msg.type.equals("pubKey")){
- pubKey = msg.content; //get public key
- String key = Arrays.toString(crypt.geteKey());
- clients[findClient(ID)].send(new Message("symmKey", "SERVER", key, msg.sender));//! //send symmetric key encrypted with public key
- }
- public void keyEncryption() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException{
- Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
- cipher.init(Cipher.ENCRYPT_MODE, pubKey);
- eKey = cipher.doFinal(key.getBlowfishKeyBytes()); //symmetric key encrypted with public key
- //System.out.println("2. cipherText= " + bytesToHex(symmKey));
- }
- else if(msg.type.equals("symmKey")){
- symmKey = (String) msg.content; //get encrypted symmetric key (must unlock with private key)
- }
- package com.socket;
- import java.io.Serializable;
- public class Message implements Serializable{
- private static final long serialVersionUID = 1L;
- public String type, sender,content, recipient;
- public Message(String type, String sender, String content, String recipient){
- this.type = type; this.sender = sender; this.content = content; this.recipient = recipient;
- }
- @Override
- public String toString(){
- return "{type='"+type+"', sender='"+sender+"', content='"+content+"', recipient='"+recipient+"'}";
- }
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- //KeyPair
- try {
- keyPair = new Keypair();
- } catch (NoSuchAlgorithmException ex) {
- jTextArea1.append("Security Error! You are not safe!");
- }
- Object pubKey = keyPair.getKeyPair().getPublic();
- username = jTextField3.getText();
- password = jPasswordField1.getText();
- if (!username.isEmpty() && !password.isEmpty()) {
- client.send(new Message("login", username, password, "SERVER"));
- client.send(new Message("pubKey",username, pubKey, "SERVER")); //send Public key to Server
- }
- }
- Database exception : userExists()
- 53846 ERROR reading: cannot assign instance of sun.security.rsa.RSAPublicKeyImpl to field com.socket.Message.content of type java.lang.String in instance of com.socket.Message
- pubKey = msg.content;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement