My problem is in encryption and decryption using RSA, in my project I need to encrypt some string using the public key and send the results via some socket to another client to decrypt it using the relative private key.
My encryption function return byte[] and I encode it to string to be able to send it also I add some other data to this string and then in the other side I break it again and get the encrypted part off and then again turn it back to byte[] form. When I try to decrypt it an error is raised:
I try to decrypt the original byte[] in the server side and I succeeded but when I convert it to string and back again to byte[] and then decrypt it the same error is appeared . I believe that the problem is in converting to and from string.
Can anyone help me to solve that?
My encryption function return byte[] and I encode it to string to be able to send it also I add some other data to this string and then in the other side I break it again and get the encrypted part off and then again turn it back to byte[] form. When I try to decrypt it an error is raised:
Code:
Exception in thread "main" javax.crypto.BadPaddingException: Data must start with zero at sun.security.rsa.RSAPadding.unpadV15(Unknown Source) at sun.security.rsa.RSAPadding.unpad(Unknown Source) at com.sun.crypto.provider.RSACipher.a(DashoA13*..) at com.sun.crypto.provider.RSACipher.engineDoFinal(DashoA13*..) at javax.crypto.Cipher.doFinal(DashoA13*..)
Can anyone help me to solve that?