Galera do GUJ,
Estou recebendo a seguinte mensgem de erro:
Exception in thread "Chat" java.lang.ClassCastException: java.lang.String cannot be cast to javax.crypto.SealedObject
at DecryptMsg.decrypt(DecryptMsg.java:51)
at GrafClient$Reader.run(GrafClient.java:268)
A linha do erro (linha 51) está em negrito e marcada como comentário.
Os códigos que estão envolvidos com a mensagem acima estão logo abaixo:
public class Reader extends Thread {
protected GrafClient cliente;
private JTextArea OutputArea;
public Reader(GrafClient c, JTextArea OutputArea) {
super("Chat");
this.cliente=c;
this.OutputArea = OutputArea;
}
public void run() {
DataInputStream in = null;
String line, result = "";
Object objcif;
try {
in = new DataInputStream(cliente.clisoc.getInputStream());
while(true){
line = in.readLine();
objcif = line;
result = DecryptMsg.decrypt(key2, objcif);
OutputArea.append(name + "> " +result +"\r\n");
}
} catch(IOException e) {
System.out.println("Reader:"+e);
}
}
}
public static String decrypt(PrivateKey privk, Object objcif) {
Cipher c;
String s ="";
SealedObject objcifrado;
try {
c = Cipher.getInstance("RSA");
c.init(Cipher.DECRYPT_MODE, privk);
// linha do erro (51)
[b]objcifrado = (SealedObject) objcif;[/b]
s = (String)objcifrado.getObject(c);
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchPaddingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidKeyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BadPaddingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return s;
}
Neste caso eu envio um objeto tipo SealedObject criptografado para o Servidor e depois que recebo dele para assim descriptografá-lo e assim compreender a mensagem.
Raphael
