I'm using RSA encryption for converting simpletext to encrypted form.
my plain text is : hello
encrypted text : [B@d7eed7
Now, how to convert encrypted text into simple plain text i'm using following code
KeyPairGenerator keygenerator = KeyPairGenerator.getInstance("RSA");
SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN");
keygenerator.initialize(1024, random);
KeyPair keypair = keygenerator.generateKeyPair();
PrivateKey privateKey = keypair.getPrivate();
PublicKey publicKey = keypair.getPublic();
Cipher cipher = Cipher.getInstance("RSA");
String arrayStr = "[b@d7eed7";
byte ciphertext = arrayStr.getBytes();
cipher.init(Cipher.DECRYPT_MODE, privateKey);
byte[] cleartext1 = cipher.doFinal(ciphertext);
System.out.println("the decrypted cleartext is: " + new String(cleartext1));
i'm getting javax.crypto.BadPaddingException: Data must start with zero
need help !!
[B@d7eed7(or at least not in the way you think).[b@77eed7, which is in string format, now i want to return it back to the original text.byte [].toString()is meaningful. You should not even be trying to take the byte [] result of encryption and converting it to character string unless you need to transfer it through a character-only channel. In that case, you should using something like base64 encoding.