Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RSA- BIgInteger Issue

Tags:

java

I want to use RSA algorithm, for encrypt and decrypt messages. Now, as RSA can encrypt and decrypt Big-integer (or Integer) value, I need the message as Big-integer value. Now, message can contain strings like "ABC 123". What can I do ? Any help or suggestion ?

like image 901
Arpssss Avatar asked Apr 25 '26 18:04

Arpssss


2 Answers

If your message is initially ascii, you can use something like:

BigInteger i = new BigInteger();
While(j < msg.length() ) {
  i += ((byte)msg.charAt(j) << (j*7));
}

For working code consult the actual JavaDocs. But basically you just want to turn your bytes or chars into a number, so the idea is you just concatenate the bits together.

like image 87
Cris Stringfellow Avatar answered Apr 27 '26 06:04

Cris Stringfellow


It can be done, by using

byte[] b = message.getBytes()
BigInteger = new BigInteger (b) 
like image 26
Arpssss Avatar answered Apr 27 '26 07:04

Arpssss



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!