Skip to content

Commit

Permalink
Merge box classes and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jvz committed Apr 27, 2021
1 parent 583f763 commit b1c0de5
Show file tree
Hide file tree
Showing 7 changed files with 308 additions and 136 deletions.
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
# JCryptoBox

JCryptoBox is a simple cryptography facade inspired by NaCl and libsodium that uses slightly more conservative cryptography standards (NIST FIPS 140).
Cryptographic APIs are exposed via `Box` and `SealedBox`.
Cryptographic APIs are exposed via the `Box` class.
By default, boxes provide 128-bit security.
This can be overridden via the system property `dev.o1c.jcryptobox.SecurityLevel` which can be set to `SECRET` (128-bit security) or `TOP_SECRET` (256-bit security).

## Usage

JCryptoBox is published to Maven Central and can be added to a normal Apache Maven build with the following dependency:

```xml
<dependency>
<groupId>dev.o1c</groupId>
<artifactId>jcryptobox</artifactId>
<version>1.0</version>
</dependency>
```

A quick overview of some APIs:

```java
import dev.o1c.jcryptobox.Box;
import dev.o1c.jcryptobox.SealedBox;

import java.nio.charset.StandardCharsets;
import java.security.KeyPair;
import java.security.PublicKey;
import java.security.SecureRandom;

class Example {
static void sealedBox() {
KeyPair alice = Box.generateKeyPair();
byte[] message = "Hello, Alice!".getBytes(StandardCharsets.UTF_8);
byte[] sealedBox = SealedBox.to(alice.getPublic()).seal(message);
byte[] sealedBox = Box.sealing(alice.getPublic()).seal(message);

byte[] decrypted = SealedBox.unseal(alice, sealedBox);
byte[] decrypted = Box.unsealing(alice).unseal(sealedBox);
}

static void boxFactory() {
Expand All @@ -45,3 +55,10 @@ class Example {
}
}
```

## Export Notice

This distribution includes cryptographic software.
The country in which you currently reside may have restrictions on the import, possession, use, and/or re-export to another country, of encryption software.
BEFORE using any encryption software, please check your country's laws, regulations and policies concerning the import, possession, or use, and re-export of encryption software, to see if this is permitted.
See https://www.wassenaar.org for more information.
42 changes: 39 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
# JCryptoBox

JCryptoBox is a simple cryptography facade inspired by NaCl and libsodium that uses slightly more conservative cryptography standards (NIST FIPS 140).
Cryptographic APIs are exposed via `Box` and `SealedBox`.
By default, boxes provide 128-bit security.
JCryptoBox is a Java cryptographic facade API inspired by [NaCl](https://nacl.cr.yp.to/) and [libsodium](https://doc.libsodium.org/).
JCryptoBox uses cryptographic algorithms compliant with NIST FIPS 140 recommendations and works with or without a certified FIPS Java cryptography library such as [BouncyCastle](https://www.bouncycastle.org/fips-java/).
Cryptographic APIs are exposed via `Box`.
By default, boxes provide 128-bit security, and this can be configured to default to 256-bit security.

## Usage

JCryptoBox is published to Maven Central and can be added to a normal Apache Maven build with the following dependency:

```xml
<dependency>
<groupId>dev.o1c</groupId>
<artifactId>jcryptobox</artifactId>
<version>1.0</version>
</dependency>
```

### Key Generation

Public and private keys can be generated via `Box.generateKeyPair()`.
By default, these are 256-bit ECDH keys using the standard NIST P.256 curve parameters.
In top secret security mode, this uses NIST P.521.
Keys can also be imported through standard Java cryptographic APIs, though that is an advanced topic.

### Encryption

Boxes provide mutual authentication and confidentiality of messages sent between two principals.
To encrypt a message from a sender to a recipient, a box is constructed from `Box.boxing()`.
To decrypt a message from a sender to a recipient, a box is constructed from `Box.opening()`.

Sealed boxes provide confidentiality and integrity of a message sent from an anonymous sender to a known recipient principal.
These can be constructed via `Box.sealing()` and `Box.unsealing()` for encryption and decryption respectively.

## Export Notice

This distribution includes cryptographic software.
The country in which you currently reside may have restrictions on the import, possession, use, and/or re-export to another country, of encryption software.
BEFORE using any encryption software, please check your country's laws, regulations and policies concerning the import, possession, or use, and re-export of encryption software, to see if this is permitted.
See https://www.wassenaar.org for more information.
Loading

0 comments on commit b1c0de5

Please sign in to comment.