Giter VIP home page Giter VIP logo

jcryptobox's Introduction

JCryptoBox

javadoc

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 the JCryptoBox 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:

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

A quick overview of some APIs:

import dev.o1c.jcryptobox.JCryptoBox;

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

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

        byte[] decrypted = JCryptoBox.unsealing(alice).unseal(sealedBox);
    }

    static void boxFactory() {
        KeyPair alice = JCryptoBox.generateKeyPair();
        KeyPair bob = JCryptoBox.generateKeyPair();

        // nonce can be any length but can only be used once per key
        byte[] nonce = new byte[16];
        SecureRandom random = SecureRandom.getInstanceStrong();
        random.nextBytes(nonce);
        // or some sequential source with networking, etc.
        byte[] message1 = "Hello, Bob! ~Alice".getBytes(StandardCharsets.UTF_8);
        byte[] box1 = JCryptoBox.boxing(alice, bob.getPublic()).box(nonce, message1);
        byte[] decrypted1 = JCryptoBox.opening(bob, alice.getPublic()).open(nonce, box1);

        random.nextBytes(nonce);
        byte[] message2 = "Greetings, Alice! ~Bob".getBytes(StandardCharsets.UTF_8);
        byte[] box2 = JCryptoBox.boxing(bob, alice.getPublic()).box(nonce, message2);
        byte[] decrypted2 = JCryptoBox.opening(alice, bob.getPublic()).open(nonce, box2);
    }
}

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.

jcryptobox's People

Contributors

jvz avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

jcryptobox's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.