I found an answer that almost solves my problem: https://mcmap.net/q/1414267/-convert-biginteger-to-shorter-string-in-java
This answer demonstrates how to encode a BigInteger into a String then back into a BigInteger using Base64 encodings which uses Apache commons-codec.
Is there a way of encoding technique/method for a String to a BigInteger then back to a String? if so would someone please explain how to use it?
String s = "hello world";
System.out.println(s);
BigInteger encoded = new BigInteger( SOME ENCODING.(s));
System.out.println(encoded);
String decoded = new String(SOME DECODING.(encoded));
System.out.println(decoded);
Print:
hello world
830750578058989483904581244
hello world
(The output is just an example and hello world doesn't have to decode to that BigInteger)
EDIT
More specific:
I am writing a RSA algorithm and I need to convert a message into a BigInteger so that I can then encrypt the message with the public key (send message) and then decrypt the message with the private key and then convert the number back into a String.
I would like a method of conversion that could produce the smallest BigInteger as I was planning on using binary until I realised how ridiculouslybig the number would be.
Is there a way of encoding technique/method for a String to a BigInteger then back to a String?
: yes. – FundamentalismString.getBytes()
? Most encryption implementations accept byte arrays not BigIntegers, I think – Criswell