项目作者: Glusk

项目描述 :
An object-oriented approach to cryptography in Java.
高级语言: Java
项目地址: git://github.com/Glusk/caesar.git
创建时间: 2020-08-12T00:50:48Z
项目社区:https://github.com/Glusk/caesar

开源协议:MIT License

下载


Caesar

Logo

Build Status
Build status
Codacy Badge
Coverage Status

Maven Central
javadoc

LoC
Hits-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:

  1. ImmutableMessageDigest imd =
  2. new ImmutableMessageDigest(
  3. MessageDigest.getInstance(/* ... */)
  4. );

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

  1. // ImmutableMessageDigest imd = ...
  2. Bytes result = new Hash(imd, new PlainText("password123"));

You can also use ImmutableMessageDigest‘s fluid API:

  1. // ImmutableMessageDigest imd = ...
  2. byte[] result = imd.update(new PlainText("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:

  1. H(H(b1), b2, b3)

This is how it would be done with Caesar:

  1. // byte[] b1 = ...
  2. // byte[] b2 = ...
  3. // byte[] b3 = ...
  4. // ImmutableMessageDigest imd = ...
  5. Bytes result =
  6. new Hash(
  7. imd,
  8. new Hash(
  9. imd,
  10. () -> b1
  11. ),
  12. () -> b2,
  13. () -> b3
  14. );

HMAC

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

  1. Bytes hmac =
  2. new Hmac(
  3. new ImmutableMessageDigest(
  4. MessageDigest.getInstance("SHA-256")
  5. ),
  6. new PlainText("Key"),
  7. new PlainText("Message")
  8. );

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:

  1. ./release.sh 0.1.1 0.1.2-SNAPSHOT

Logo icon made by Pixelmeetup from www.flaticon.com