Skip to content

libsodium compatible CryptoSign, SealedBox and SecretBox implementation in Java

License

Notifications You must be signed in to change notification settings

xconnio/cryptology-java

Repository files navigation

CryptologyJava

libsodium compatible CryptoSign, SealedBox and SecretBox implementation in Java.

Download

Include in your project using Maven:

<dependency>
    <groupId>io.xconn</groupId>
    <artifactId>cryptology</artifactId>
    <version>1.1.2</version>
</dependency>

Or with Gradle:

implementation 'io.xconn:cryptology:1.1.2'

Usage

CryptoSign

Generate ED25519 KeyPair

KeyPair keyPair = CryptoSign.generateKeyPair();

Get PublicKey from PrivateKey

byte[] privateKey = // ED25519 private key bytes
byte[] publicKey = CryptoSign.getPublicKey(privateKey);

Sign Message

byte[] privateKey = // ED25519 private key bytes
byte[] message = "Hello, world!".getBytes();
byte[] signature = CryptoSign.sign(privateKey, message);

SealedBox

Seal Message

byte[] recipientPublicKey = // X25519 recipient's public key bytes
byte[] message = "Secret message".getBytes();
byte[] encryptedMessage = SealedBox.seal(message, recipientPublicKey);

Open Sealed Message

byte[] privateKey = // X25519 recipient's private key bytes
byte[] sealedMessage = // Sealed message bytes
byte[] decryptedMessage = SealedBox.sealOpen(sealedMessage, privateKey);

SecretBox

Encrypt Message

byte[] nonce = SecretBox.generateNonce();
byte[] secretKey = SecretBox.generateSecret();
byte[] message = "Secret message".getBytes();
byte[] encryptedMessage = SecretBox.box(nonce, message, secretKey);

Decrypt Message

byte[] nonce = // Nonce bytes
byte[] secretKey = // Secret key bytes
byte[] sealedMessage = // Sealed message bytes
byte[] decryptedMessage = SecretBox.boxOpen(sealedMessage, nonce, secretKey);

About

libsodium compatible CryptoSign, SealedBox and SecretBox implementation in Java

Resources

License

Stars

Watchers

Forks

Packages

No packages published