/cactoos-crypto

Crypto extensions for Cactoos library

Primary LanguageJavaMIT LicenseMIT

WARNING

It was an experiment repository, it contains POC library code. It's not producation ready. It'll be not supported.


cactoos-crypto

EO principles respected here Managed by Zerocracy DevOps By Rultor.com

Bintray Build Status PDD status License Test Coverage

Cryptography extensions for Cactoos library.

Cipher as input/output

To encrypt/decrypt an input:

final Scalar<Cipher> cipher = new CipherFrom(
    "AES/CBC/PKCS5Padding",
    new CipherSpec(key, iv)
);
final Input encrypted = new CryptoInput.Enc(
  new InputOf(file),
  cipher
);
final Input decrypted = new CryptoInput.Dec(
  encrypted,
  cipher
);

To encrypt/decrypt an output:

final Scalar<Cipher> cipher = new CipherFrom(
    "AES/CBC/PKCS5Padding",
    new CipherSpec(key, iv)
);
final Output decrypting = new CryptoOutput.Dec(
  new OutputTo(file),
  cipher
);
final Output encrypting = new CryptoOutput.Enc(
  decrypting,
  cipher
);

MAC (Message Authentication Code) as Bytes:

To compute MAC of input:

final Bytes hmac = new MacOf(
  new InputOf(file),
  new MacFrom(
    "HmacSHA256",
    new MacSpec(key)
  )
);

MessageDigest as Bytes:

To compute message-digest of input:

final Bytes digest = new DigestOf(
  new InputOf(file),
  new DigestFrom("SHA-256")
);

Install

mvn:

<dependency>
  <groupId>com.g4s8</groupId>
  <artifactId>cryptocactoos</artifactId>
</dependency>

gradle:

  "com.g4s8:cryptocactoos:<vesion>"