PLEASE HELP!!! String conversion problem with BigInteger class

G

Gandu

Could some Java guru please point out what I am doing wrong? I have
created a simple RSA class using java.math.BigInteger. In public
static void main(...) I
have:
RSA rsa = new RSA();
rsa.genKeys();
rsa.showKeys();
String str = new String("This is RSA test");
byte [] byteArray = str.getBytes();
BigInteger bigInt = new BigInteger(byteArray);
BigInteger result = rsa.decrypt(rsa.encrypt(bigInt));
if(result != null){
String str1 = new String(result.toByteArray());
System.out.println(str1);
}

The print statement prints a starnge looking String. However, if I use
BigInteger bigInt = new BigInteger("1234567890");
instead of BigInteger bigInt = new BigInteger(byteArray); in above,
the
output is 1234567890
Could someone please point out what I am doing wrong? Thanks in
advance for
your help.
 
M

Michael Borgwardt

Gandu said:
The print statement prints a starnge looking String. However, if I use
BigInteger bigInt = new BigInteger("1234567890");
instead of BigInteger bigInt = new BigInteger(byteArray); in above,
the
output is 1234567890

It shouldn't. Either the code you've posted isn't the one you're
running or it's not that code that does the printing. Or something
is seriously wrong with your RSA code.

http://www.physci.org/codes/sscce.jsp
Could someone please point out what I am doing wrong?

The code ypu've posted looks right.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,817
Latest member
AdalbertoT

Latest Threads

Top