1

I decrypted a data and got a BigInt and when I tried to convert it to string I got some Wired characters.

Code for getting BigInteger

BigInteger dec = process.Decrypt(sec);

Code for getting ByteArray

byte testBy[] = dec.toByteArray();

Code for Converting into String

String ss = new String(testBy);
System.out.println(ss);

and I tried this code too

String ss = new String(testBy);
System.out.println(ss, "UTF8");

I'm getting this output

=^ö½ß‡k+Éæ‚ûŽ3B‚+…Òæ?&¶?kÛUô—c

Help me out here..

5
  • tutorialspoint.com/java/math/biginteger_tostring_radix.htm Commented Feb 23, 2014 at 16:29
  • 1
    why do you need the byte array? Just use BigInteger.toString() method Commented Feb 23, 2014 at 16:31
  • Pretty sure there is no println(String, String) method. Also, String ss = new String(testBy, "UTF-8"); would be acceptable. Commented Feb 23, 2014 at 16:35
  • What is process.Decrypt? Sure it returns a BigInteger, but if it is supposed to hold a String we will need more information about how this method actually stores data inside the BigInteger. Check its API documentation. Commented Feb 23, 2014 at 16:38
  • @AnthonyAccioly I'm trying an decryption of an encrypted data here is the code return c.modPow(lambda, nsquare).subtract(BigInteger.ONE).divide(n).multiply(u).mod(n); Commented Feb 23, 2014 at 16:45

3 Answers 3

16

BigInteger has a toString() method, which gives a decimal string representation of the value.

Sign up to request clarification or add additional context in comments.

5 Comments

NOTE : public String toString(int radix) ; else default value of 10
@DonRoby so how can i convert that bigInt to original text. i mean decrypted text
Sivashankar, you asked your question wrong. this is clearly a XY problem here. You don't want a String representing the number that the BigInteger holds. You want the decrypted text. And the answer is, we can't help you without knowing your library (there is a gazillion ways in which the decrypted data can be stored inside the BigInteger, plus another gazillion things that the data can really be).
@AnthonyAccioly let me put in another way when i give a small data file the above code is working properly but if i gave a large data file it's showing that above output. Large means just a 20kb file.
We still can't help you Sivas. The point is, you are asking for specific details of a implementation that we know nothing about. It can be a bug, there can be something missing, or it can be designed that way - we don't know. If this is code you own, debug the encryption process; if it is a library, read its documentations. If it is a popular / well known cryptography library ask a new question about "How can I decrypt my file using library XXX" and providing relevant details about how you have encrypted it.
1

A call to System.out.println(dec) should print the decimal representation of dec correctly.

So just make sure that BigInteger dec = process.Decrypt(sec) yields the expected result.

Comments

0

toString() method convert BigInteger to String.Actually it overrides the Object toString() method.Or directly pass BigInteger object to System.out.println() because println bydefault takes Object.toString().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.