Skip to content

Repository files navigation

Caesar

Logo

Build StatusBuild statusCodacy BadgeCoverage Status

Maven Centraljavadoc

LoCHits-of-Code

An object-oriented approach to cryptography in Java.


Motivation

This project aims to replace/wrap the following JDK APIs: MessageDigest, Mac and Cipher.

cactoos-crypto is a direct alternative to this project.

Hashing

In order to start using Caesar's hashing utilities you first have to wrap a MessageDigest instance inside a new ImmutableMessageDigest object:

ImmutableMessageDigestimd =
newImmutableMessageDigest(
MessageDigest.getInstance(/* ... */)
);

Once you obtain an ImmutableMessageDigest instance, you can perform the hashing:

// ImmutableMessageDigest imd = ...Bytesresult = newHash(imd, newPlainText("password123"));

You can also use ImmutableMessageDigest's fluid API:

// ImmutableMessageDigest imd = ...byte[] result = imd.update(newPlainText("password123")).digest();

Embedded hashes

You can pass the result of one hashing operation as an argument to another.

Suppose we wanted to compute the following hash:

H(H(b1), b2, b3)

This is how it would be done with Caesar:

// byte[] b1 = ...// byte[] b2 = ...// byte[] b3 = ...// ImmutableMessageDigest imd = ...Bytesresult = newHash(
imd,
newHash(
imd,
() -> b1
),
() -> b2,
() -> b3
);

HMAC

This is how you compute HMAC("Key", "Message") with Caesar, using the SHA-256 hash function:

Byteshmac =
newHmac(
newImmutableMessageDigest(
MessageDigest.getInstance("SHA-256")
),
newPlainText("Key"),
newPlainText("Message")
);

Releases

Use the release script with the following arguments:

  1. release - the next release version

  2. snapshot - the next snapshot version

  3. dryRun (optional) - if set to true, the changes will not be pushed to the remote repository

Example:

./release.sh 0.1.1 0.1.2-SNAPSHOT

Logo icon made by Pixelmeetup from www.flaticon.com

About

An object-oriented approach to cryptography in Java.

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages