https://github.com/instantwebp2p/tweetnacl-java
TweetNaCl in Java - a port of TweetNaCl-js
https://github.com/instantwebp2p/tweetnacl-java
cryptographic nacl tweetnacl
Last synced: 18 days ago
JSON representation
TweetNaCl in Java - a port of TweetNaCl-js
- Host: GitHub
- URL: https://github.com/instantwebp2p/tweetnacl-java
- Owner: InstantWebP2P
- License: mit
- Created: 2014-10-21T00:23:22.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2023-02-03T11:13:15.000Z (over 2 years ago)
- Last Synced: 2025-07-18T09:10:13.138Z (3 months ago)
- Topics: cryptographic, nacl, tweetnacl
- Language: Java
- Homepage: https://instantwebp2p.github.io/tweetnacl-java
- Size: 260 KB
- Stars: 48
- Watchers: 5
- Forks: 28
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
TweetNacl in Java: port of [tweetnacl-js](https://github.com/dchest/tweetnacl-js)
====================================================================
### Download
#### Using Gradle
```
implementation "io.github.instantwebp2p:tweetnacl-java:1.1.2"
```### API/Usage
### Suggest always use [TweetNaclFast](https://github.com/InstantWebP2P/tweetnacl-java/blob/master/src/main/java/com/iwebpp/crypto/TweetNaclFast.java) implementation
#### Public key authenticated encryption
* get key pair: Box.KeyPair kp = Box.keyPair(), kp = Box.keyPair_fromSecretKey(sk)
* new Box object: Box box = new Box(theirPublicKey, mySecretKey, Nonce);
* encryption: cipher = box.box(message);
* decryption: message = box.open(cipher);
* Nonce MUST be unique for ever message passed between same peersAs an alternative, the nonce can be omitted from the Box() call, and passed in the box and open calls, like:
* byte [] nonce = new byte[nonceLength], randombytes(theNonce, nonceLength);
* Box.KeyPair kp = Box.keyPair(), kp = Box.keyPair_fromSecretKey(sk)
* Box box = new Box(theirPublicKey, mySecretKey);
* encryption: cipher = box.box(message, nonce);
* decryption: message = box.open(cipher, nonce);#### Secret key authenticated encryption
* get shared key: crypto random, what you have
* new SecretBox object: SecretBox sbox = new SecretBox(sharedKey, Nonce);
* encryption: cipher = sbox.box(message);
* decryption: message = sbox.open(cipher);
* Nonce MUST be unique for ever message passed between same peersAs an alternative, the nonce can be omitted from the SecretBox() call, and passed in the box and open calls, like:
* byte [] nonce = new byte[nonceLength], randombytes(theNonce, nonceLength);
* SecretBox sbox = new SecretBox(sharedKey);
* cipher = sbox.box(message, nonce);
* decryption: message = sbox.open(cipher, nonce);### Signature
* get key pair: Signature.KeyPair kp = Signature.keyPair(), kp = Signature.keyPair_fromSecretKey(sk);
* new Signature object: Signature sig = new Signature(theirPublicKey, mySecretKey);
* sign: signedMessage = sig.sign(message);
* verify: message = sig.open(signedMessage);
* Nonce MUST be unique for ever message passed between same peers### Hash
* generate SHA-512: byte [] tag = Hash.sha512(message);
### Refer to com.iwebpp.crypto.tests for details
### About Random generation
* the library uses java.security.SecureRandom for key generation
* you can always use the library to generate key, or use a Crypto Random like java.security.SecureRandom### Testing
In top directory:
$ mvn test
### Support us
* Welcome contributing on document, codes, tests and issues
### License MIT
* Copyright(2014-present) by tom zhou, appnet.link@gmail.com