【发布时间】:2017-09-25 15:10:46
【问题描述】:
收到string 无法转换为byte[] 的错误:
String decrypted = new String(cipher.doFinal(msgin));
这是正确的加密方法,因为我收到的是加密形式的消息。
try{
String msgout = "";
msgout = msg_text.getText().trim();
aesKey = new SecretKeySpec(key.getBytes(), "AES");
cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, aesKey);
encrypted = cipher.doFinal(msgout.getBytes());
String msgout1;
msgout1 = String.valueOf(encrypted);
dout.writeUTF(msgout1);
msg_area.setText(msg_area.getText().trim()+"\nYou:\t"+msgout);
}catch(Exception e){
}
这是解密
的显示消息 String msgin = "";
try{
ss = new ServerSocket(1201);
s = ss.accept();
din = new DataInputStream(s.getInputStream());
dout = new DataOutputStream(s.getOutputStream());
while(!msgin.equals("exit")){
msgin = din.readUTF();
cipher.init(Cipher.DECRYPT_MODE, aesKey);
String decrypted = new String(cipher.doFinal(msgin));\\here am receving error that string cannot be convert to byte[]
msg_area.setText(msg_area.getText().trim()+"\nClient:\t"+decrypted);
}
}catch(Exception e){
}
有什么解决办法吗?
【问题讨论】:
标签: java arrays string type-conversion byte