Prev: Properties.list(System.err) not listing strings?
Next: One Of The Easiest Ways To Promote Your Site!
From: Albretch Mueller on 26 Dec 2009 03:08 I justnoticed that Linux's sha256sum of a binary file ~ $ sha256sum -b *.bin 035dfc8af407ad305c9b6ad9c265efb57cc283684a37e7b94853c7aa76919ad0 *p69.bin ~ and java sha-256 signatures were not the same because (new BigInteger (1, MD.digest())).toString(16) discards the leading 0's producing ~ 35dfc8af407ad305c9b6ad9c265efb57cc283684a37e7b94853c7aa76919ad0 ~ How do you deal with these subtle differences without a hack? Is there a way to instruct BigInteger to keep leading 0's? Or anyother way to do that?
From: alexandre_paterson on 26 Dec 2009 05:53 On Dec 26, 9:08 am, Albretch Mueller <lbrt...(a)gmail.com> wrote: > I justnoticed that Linux's sha256sum of a binary file > ~ > $ sha256sum -b *.bin > *p69.bin > ~ > and java sha-256 signatures were not the same because (new BigInteger > (1, MD.digest())).toString(16) discards the leading 0's producing > ~ > 35dfc8af407ad305c9b6ad9c265efb57cc283684a37e7b94853c7aa76919ad0 > ~ > How do you deal with these subtle differences without a hack? Is > there a way to instruct BigInteger to keep leading 0's? Or anyother > way to do that? Left padding. It's not a hack. It's not hard to write a left pad method yourself. Jakarta commons's StringUtils has a leftPad method. Or you logical OR your BigInteger with a bigint that has its 257 bit set then you discard the char at 0. Both would work and are really simple.
From: alexandre_paterson on 26 Dec 2009 05:56 On Dec 26, 11:53 am, alexandre_pater...(a)yahoo.fr wrote: > On Dec 26, 9:08 am, Albretch Mueller <lbrt...(a)gmail.com> wrote: > > > I justnoticed that Linux's sha256sum of a binary file > > ~ > > $ sha256sum -b *.bin > > *p69.bin > > ~ > > and java sha-256 signatures were not the same because (new BigInteger > > (1, MD.digest())).toString(16) discards the leading 0's producing > > ~ > > 35dfc8af407ad305c9b6ad9c265efb57cc283684a37e7b94853c7aa76919ad0 > > ~ > > How do you deal with these subtle differences without a hack? Is > > there a way to instruct BigInteger to keep leading 0's? Or anyother > > way to do that? > > Left padding. It's not a hack. It's not hard to write a left pad > method yourself. Replying to myself, taking a quick look at the BigInteger method there's this: zeros[63] = "000000000000000000000000000000000000000000000000000000000000000"; Which screams padding :) Googling-on-"padding"-is-your-friend :)
From: Albretch Mueller on 26 Dec 2009 10:38 > Left padding. It's not a hack. ~ well, I see. I could go " ...".endsWith() and then make sure that the left side matches all 0's or I may use the DecimalFormat class ... ~ I just thought BigInteger or some Base16 method in java which does not assume you are converting a number, would do ~ By the way. Where does java stash its Base{16, 32, 64} libraries? is there any way to easily/reliably access them, or will I have to use the jakarta commons libraries? ~ lbrtchx
From: Mike Schilling on 26 Dec 2009 11:37 Albretch Mueller wrote: >> Left padding. It's not a hack. > ~ > well, I see. I could go " ...".endsWith() and then make sure that > the > left side matches all 0's or I may use the DecimalFormat class ... Or simply pad with 2 * array.length - string.length() zeros
|
Next
|
Last
Pages: 1 2 3 Prev: Properties.list(System.err) not listing strings? Next: One Of The Easiest Ways To Promote Your Site! |