Sending data byte [] socket

0

I have a problem a few days that I can not solve.

I have a socket connection and I'm testing signature in the messages, I have a Mensagem object that contains String mensagem , String assinatura and PublicKey chavePublica , in my client I ask for a text entry with Scanner, Message object that I will send through socketClient.write(mensagem) everything works as expected except for the signature, follow the flow:

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

That is, my signature is in byte[] , I keep 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 this String to byte[] again, it's not the same byte[] , the problem is not the socket because even in the same class I have this problem, String but does not return equal to byte[] . Can someone 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 Byte

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

    
asked by anonymous 07.03.2018 / 13:47

0 answers