I'm implementing the following RSA algorithm.
http://www.sanfoundry.com/java-program-implement-rsa-algorithm/ The program picks up a string from an excel file, performs the RSA algorithm and stores that string (string of bytes) into the database.
While decrypting, I need to extract that string of bytes, convert it into a byte array to perform decryption.
protected String encryptit(String teststring) {
RSA rsa = new RSA();
DataInputStream in = new DataInputStream(System.in);
BigInteger e = rsa.getE();
//String es=e.toString();
BigInteger N = rsa.getN();
BigInteger d=rsa.getD();
try {
byte[] encrypted = encrypt(teststring.getBytes(),e,N);
String encryptString = encrypted.toString();
return encryptString;
}
catch(Exception ex) {
System.out.println(ex);
return "0";
}
}
The above function performs encryption. One of the values that gets stored is [B@37ad7b17
protected String decrypt(String val)
{
System.out.println("Value " +val);
RSA rsa = new RSA();
BigInteger e = rsa.getE();
BigInteger N = rsa.getN();
BigInteger d=rsa.getD();
try {
String[] bytesString = val.split(" ");
byte[] bytes = new byte[bytesString.length];
for(int i=0;i<bytes.length;i++)
{
System.out.println("for loop");
bytes[i]=Byte.parseByte(bytesString[i]);
}
byte[] decrypted= decrypt(bytes,d,N);
String decryptString = new String(decrypted);
System.out.println(decryptString);
return decryptString;
}catch(Exception ex) {
System.out.println(ex);
return "0";
}
}
The above function performs the decryption. And it gives java.lang.NumberFormatException: For input string: "[B@37ad7b17"
What should I do to convert this string of bytes to a byte array.