MCPcopy Index your code
hub / github.com/InstantWebP2P/tweetnacl-java

github.com/InstantWebP2P/tweetnacl-java @v1.1.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.1.2 ↗ · + Follow
425 symbols 1,232 edges 12 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

TweetNacl in Java: port of tweetnacl-js

Java CI

API/Usage

Suggest always use TweetNaclFast 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 peers

As 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 peers

As 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

Core symbols most depended-on inside this repo

gf
called by 57
bench/nacl-fast.js
gf
called by 57
bench/nacl.js
getPublicKey
called by 46
src/main/java/com/iwebpp/crypto/TweetNacl.java
getSecretKey
called by 46
src/main/java/com/iwebpp/crypto/TweetNacl.java
M
called by 34
src/main/java/com/iwebpp/crypto/TweetNacl.java
M
called by 34
src/main/java/com/iwebpp/crypto/TweetNaclFast.java
M
called by 34
tweetnacl/tweetnacl.c
M
called by 34
bench/nacl-fast.js

Shape

Method 219
Function 185
Class 21

Languages

Java56%
TypeScript29%
C14%
C++1%

Modules by API surface

src/main/java/com/iwebpp/crypto/TweetNacl.java110 symbols
src/main/java/com/iwebpp/crypto/TweetNaclFast.java104 symbols
bench/nacl.js68 symbols
tweetnacl/tweetnacl.c61 symbols
bench/nacl-fast.js54 symbols
src/test/java/com/iwebpp/crypto/TweetNaclFastTest.java12 symbols
src/test/java/com/iwebpp/crypto/TweetNaclTest.java11 symbols
src/test/java/com/iwebpp/crypto/Log.java3 symbols
bench/bench.cpp2 symbols

For agents

$ claude mcp add tweetnacl-java \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact