[英]Rebuild byte array with bigInteger and other method
當我進行簽名編碼時,遇到一個陌生人的問題:
當我想重建一個字節數組時,它總是失敗:
//digest is the original byte array
String messageHex = bytesToHex(digest);
byte[] hexRestore = messageHex.getBytes();
assert Arrays.equals(digest, hexRestore); //false!
String utf8Digest = new String(digest, "UTF8");
byte[] utf8Restore = utf8Digest.getBytes("UTF8");
assert Arrays.equals(digest, utf8Restore); //false!
然后,我使用大整數:
BigInteger messageBig = new BigInteger(digest);
byte[] bigRestore = messageBig.toByteArray();
assert Arrays.equals(digest, bigRestore)); //true!
然后它起作用了,我不知道為什么,c
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.