libsodium compatible CryptoSign, SealedBox and SecretBox implementation in Java.
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'
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);
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);
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);