我尝试从字符串中获取大数字,但二进制值是错误的。
priKeyData = HexByteKit.Hex2Byte("b8dfc598d14c0bb032c1f4eb1fcdb033289002f38cc16b2120dfa697f8982bef");
BigInteger priKeyBN2 = new BigInteger(priKeyData);
String s3 = priKeyBN2.toString(2);
它给出: -1000111001000000011101001100111001011101011001111110100010011111100110100111110000010110001010011100000001100100100111111 001100110101110110111111111101000011000111001100111110100101001101111011011111001000000101100101101000000001110110011111010 10000010001
但正确的应该是:
10111000110111111100010110011000110100010100110000001011101100000011001011000001111101001110101100011111110011011011000 000110011001010001001000000000010111100111000110011000001011010110010000100100000110111111010011010010111111110001001100000 10101111101111
http://www.mobilefish.com/services/big_number/big_number.php
右边的是256位,所以在Java bignumber类中会溢出? 那么如何在Java加密算法的某些步骤中使用这个256位数字呢?
谢谢。
最佳答案
我不知道 HexByteKit
是什么,但从十六进制字符串构造 BigInteger
给出了正确的结果:
BigInteger priKeyBN2 = new BigInteger("b8dfc598d14c0bb032c1f4eb1fcdb033289002f38cc16b2120dfa697f8982bef", 16);
String s3 = priKeyBN2.toString(2);
关于Java 大数负数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41062253/