Sending byte[] socket data

Asked

Viewed 125 times

0

I’ve had a problem for a few days that I can’t fix.

I have a socket connection and I am testing signature on messages, I have an object Mensagem that contain String mensagem, String assinatura and PublicKey chavePublica, on my client I request a text input with Scanner, then mount the Message object that I will send through socketClient.write(mensagem) everything works as expected except for the signature, follows the flow:

Byte[] -> Base64 Encode -> String -> Socket Write -> Get Bytes -> Base64 Decode -> Byte[]

I mean, my signature is on byte[], I keep in the same type when doing Encode 64, OK. After that I use new String(assinatura, "ISO-8859-1") and the signature turns:

MCwCFE2V4wamcL/3FpjXXjHcEXcNWsohAhQTVoOLVmaxkazBgRsw0ZDGi3Mzkg==

The socket gets ok, but when I try to get back from that String for byte[] again, it’s not the same byte[], the problem is not the socket because even in the same class I have this problem, I turn into String but does not return equal to byte[]. Someone can help me?

Transforming into String

byte[] assinatura = cripto.assinar(mensagem); byte[] assinatura64 = Base64.encodeBase64(assinatura); //Byte[] to Byte[] 64Encode String assinaturaStr = new String(assinatura64, "ISO-8859-1"); //Byte[] to String

Returning to the Byte

String assinatura = mensagem.getAssinatura(); //Retorna a String correta assinada byte[] assinaturaBytes = assinatura.getBytes("ISO-8859-1"); byte[] assinaturaBytes64 = Base64.decodeBase64(assinaturaBytes);

  • Add the relevant chunk that does the code conversion.

  • Edited content, this the way I do the conversions, neither the signing readBytes nor the signing Bytes64 is equal to the signature I generated.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.