I'm trying to simulate the RSA encryption and decryption I want the encryption method to
- Take the string
- convert it into byte []
- do the RSA function (as I will show in the following code)
- return the byte [] as a string
what I have now and it works but with receiving and returning byte [] (not string)
public byte[] encrypt (byte[] message){
byte [] t= ((new BigInteger(message)).modPow(e, N)).toByteArray();
return (t);
}
the decrypt method I want it to
- receive the returned String from encrypt()
- convert it into byte[]
- do the RSA on the byte[] to get the original byte []
return the original string what I have up until now
public byte [] decrypt (byte [] message) { byte[] data= ((new BigInteger(message)).modPow(d, N)).toByteArray(); return data; }
these 2 methods work, but I need to create a byte [] in my main class and use byte[]Str.getbyte() to encrypt and new String(byte []) to encrypt .....
I want my main to deal with only strings. When I use such a decrypt(String message) code
public String decrypt (String message) {
byte[] data= ((new BigInteger(message.getBytes())).modPow(d, N)).toByteArray();
return data.toString();
}
it doesn't give me the original text as it does with decrypt(byte [] message), but it returns something like B@79f0a8b
I'm sure I'm missing something related to converting the text into byte[] and vice versa, but I'm not sure what am I missing.
I would love to hear from you.
(sorry for my English)