The value I got by using java.util.zip.CRC32 is always inconsistent with that obtained by UNIX cksum. I tried many methods but failed. What should I do? https://introcs.cs.princeton.edu/java/61data/CRC32.java.html
Asked
Active
Viewed 126 times
0
-
How can we know what's wrong without seeing your code? or is that link your actual code? – g00se Sep 23 '21 at 12:47
-
@索蒂里奥斯·德利马诺利斯Thank you very much. You're right, but I don't want to use cksum - O 3. How can I use java.util.zip.crc32? – 吉光片羽幻成仙 Sep 23 '21 at 13:10
-
@g00se Thank you very much,My problem is cksum -o 3 – 吉光片羽幻成仙 Sep 23 '21 at 13:12
-
Afaics, `cksum` is not the same as `crc32`. The latter gives the same output as your Java app, *not* the former. fwiw `cksum -o 3` produces this for me: *cksum: invalid option -- 'o'* – g00se Sep 23 '21 at 13:15
-
@g00se Well, I use cksum -- version to check the version. It is cksum (coreutils) 8.4. What should I do without cksum -o 3 – 吉光片羽幻成仙 Sep 23 '21 at 13:43
-
Why not use, as I did, crc32, which is in package libarchive-zip-perl? – g00se Sep 23 '21 at 13:46
-
@g00se Sorry, I can't use that, because the customer uses this to verify the file, and can't use other methods. What should I do? – 吉光片羽幻成仙 Sep 23 '21 at 13:53
-
https://stackoverflow.com/questions/7746476/java-compatible-cksum-function – Sep 23 '21 at 14:02
-
@dratenik sorry,I saw it, but I don't quite understand whether I can continue to use java to generate it. Can you teach me – 吉光片羽幻成仙 Sep 23 '21 at 14:23
-
cksum in coreutils, for me at least, produces a different number – g00se Sep 23 '21 at 14:28
-
@g00se lol,If the customer has to generate it like this, I can't do it. I can't generate the same check code as cksum – 吉光片羽幻成仙 Sep 23 '21 at 14:34
-
The linked answer points to a java library, where [jonelo.jacksum.algorithm.Cksum](https://github.com/gusmp/appletCatcertDI/blob/master/src/main/java/jonelo/jacksum/algorithm/Cksum.java) does the checksum you want. Call it the same as java.util.zip.CRC32 in your sample. Its license is GPLv2 which may be a problem, no idea what your circumstances are. – Sep 23 '21 at 14:37
-
Apparently the reason cksum doesn't play ball is that it uses CRC16 ;) – g00se Sep 23 '21 at 14:50
-
@g00se LOL,solved – 吉光片羽幻成仙 Sep 24 '21 at 01:27
-
@dratenik Oh~Oh, it's great. It solved my problem. Thank you very much! – 吉光片羽幻成仙 Sep 24 '21 at 01:29
-
Please provide enough code so others can better understand or reproduce the problem. – Community Sep 30 '21 at 17:56