Commons Checksum

Commons Checksum provides functional utilities for working with common checksums and hashes such as CRC-32, Adler-32, MD5 and SHA-1.

License

License

GroupId

GroupId

com.github.qlefevre
ArtifactId

ArtifactId

commons-checksum
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

Commons Checksum
Commons Checksum provides functional utilities for working with common checksums and hashes such as CRC-32, Adler-32, MD5 and SHA-1.
Project URL

Project URL

http://github.com/qlefevre/commons-checksum/
Project Organization

Project Organization

Commons Checksum
Source Code Management

Source Code Management

https://github.com/qlefevre/commons-checksum

Download commons-checksum

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.qlefevre/commons-checksum/ -->
<dependency>
    <groupId>com.github.qlefevre</groupId>
    <artifactId>commons-checksum</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.qlefevre/commons-checksum/
implementation 'com.github.qlefevre:commons-checksum:1.0.0'
// https://jarcasting.com/artifacts/com.github.qlefevre/commons-checksum/
implementation ("com.github.qlefevre:commons-checksum:1.0.0")
'com.github.qlefevre:commons-checksum:jar:1.0.0'
<dependency org="com.github.qlefevre" name="commons-checksum" rev="1.0.0">
  <artifact name="commons-checksum" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.qlefevre', module='commons-checksum', version='1.0.0')
)
libraryDependencies += "com.github.qlefevre" % "commons-checksum" % "1.0.0"
[com.github.qlefevre/commons-checksum "1.0.0"]

Dependencies

test (3)

Group / Artifact Type Version
junit : junit jar 4.10
commons-codec : commons-codec jar 1.6
org.bouncycastle : bcprov-ext-jdk16 jar 1.46

Project Modules

There are no modules declared in this project.

commons-checksum Maven Central Build Status Coverage

Commons Checksum provides functional utilities for working with common checksums and hashes. Project relies on the great utilities providing by the DigestUtils class of Apache Commons Codec project.

The class org.apache.commons.codec.digest.DigestUtils was improved to handle new algorithms such as:

  • MD2
  • MD4
  • MD5
  • RIPEMD-128
  • RIPEMD-160
  • RIPEMD-256
  • RIPEMD-320
  • SHA-1
  • SHA-224
  • SHA-256
  • SHA-384
  • SHA-512
  • Tiger
  • Whirlpool

A new class ChecksumUtils which extends DigestUtils was added. It handles checksum algorithms such as :

  • Adler-32
  • CRC-32
  • Fletcher-32

Installation

To use the latest release of commons-checksum, please use the following snippet in your pom.xml.

<dependency>
    <groupId>com.github.qlefevre</groupId>
    <artifactId>commons-checksum</artifactId>
    <version>1.0.0</version>
</dependency>

Two Minute Tutorial

There are six method signatures for each algorithm as described below :

public static byte[] md2(byte[] data)
public static byte[] md2(InputStream data) throws IOException
public static byte[] md2(String data)
public static String md2Hex(byte[] data)
public static String md2Hex(InputStream data) throws IOException
public static String md2Hex(String data)

Calculating the checksum of a byte array

public static final byte[] HELLO_WORLD_BYTE_ARRAY = "Hello World".getBytes();
String crc32Hex = ChecksumUtils.crc32Hex(HELLO_WORLD_BYTE_ARRAY);
String sha512Hex = ChecksumUtils.sha512Hex(HELLO_WORLD_BYTE_ARRAY);

Calculating the checksum of a String

public static final String HELLO_WORLD_STRING = "Hello World";
String md5Hex = ChecksumUtils.md5Hex(HELLO_WORLD_STRING);
String whirlpoolHex = ChecksumUtils.whirlpoolHex(HELLO_WORLD_STRING);

Note

Oracle JDK 8 offers 7 digest algorithms : MD2, MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512.

Digest Oracle JDK 1.8> Oracle JDK 1.6> Bouncy Castle
MD2 yes yes yes
MD4 no no yes
MD5 yes yes yes
RIPEMD-128 no no yes
RIPEMD-160 no no yes
RIPEMD-256 no no yes
RIPEMD-320 no no yes
SHA-1 yes yes yes
SHA-224 yes no yes
SHA-256 yes yes yes
SHA-384 yes yes yes
SHA-512 yes yes yes
Tiger no no yes
Whirlpool no no yes

See:

  • Bouncy Castle : org.bouncycastle.jce.provider.JDKMessageDigest
  • Sun : sun.security.provider.Sun

Configuring Bouncy Castle

If you have a mavenized project, you can add this dependency :

<dependency>
 <groupId>org.bouncycastle</groupId>
 <artifactId>bcprov-ext-jdk16</artifactId>
 <version>1.46</version>
</dependency>

You can now use the Whirlpool digest. You just have to register the provider programatically

Security.addProvider(new BouncyCastleProvider());
String whirlpool = whirlpool2Hex("Hello world !"); 

Versions

Version
1.0.0