NaCl and libsodium compatible library for public-key cryptography and hashing using Bouncy Castle.
Secret key cryptography is not supported. PRs to add secret key cryptography to this library will be accepted.
- Ed25519
- ECDSA
- secp256k1
- SHA1
- SHA2 (SHA-256, SHA-384, SHA-512)
- SHA3 (SHA3-256, SHA3-384, SHA3-512)
- Blake2b (Blake2b-256, Blake2b-384, Blake2b-512)
- Keccak (Keccak-256, Keccak-384, Keccak-512)
Create an ECDSARecovery object using Bouncy Castle's X9ECParameters or a String to specify the curve and Bouncy Castle's Digest to specify the hash algorithm, with default one being SHA-256.
Signatures created from ECDSARecovery will have attached v
(recId) as a header byte to the signature.
Create an ECDSA object using Bouncy Castle's X9ECParameters or a String to specify the curve and Bouncy Castle's Digest to specify the hash algorithm, with default one being SHA-256.
Signatures created from ECDSA will NOT have attached v
(recId) as a header byte to the signature.
Create an Ed25519 object.
Create a random KeyPair.
Create a KeyPair from seed.
Create a KeyPair from a private key.
Sign a message using a private key or a KeyPair. The return value is the digital signature of type Binary.
Verify a signature using a public key or a KeyPair.
A sign
method which prepends the message to the signature, compatible with
libsodium's combined mode,
is not yet supported.
Create an ECDSARecovery
object, using secp256k1
curve with default Keccak-256
digest,
hash a message, create a KeyPair, sign a message and verify it.
ECDSARecovery secp256k1 = new ECDSARecovery("secp256k1");
Hasher hasher = new Hasher("Keccak-256");
KeyPair myKeyPair = secp256k1.keyPair();
Binary msgHash = hasher.hash("Hello");
Signature mySignature = secp256k1.signDetached(myMessage, myKeyPair);
assert sig.getBytes().length == 65; // including header recId byte
secp256k1.verify(myMessage, mySignature, myKeyPair) // True
Create an ECDSA
object, using secp256k1
curve with default Keccak-256
digest,
hash a message, create a KeyPair, sign a message and verify it.
ECDSA secp256k1 = new ECDSA("secp256k1");
Hasher hasher = new Hasher("Keccak-256");
KeyPair myKeyPair = secp256k1.keyPair();
Binary msgHash = hasher.hash("Hello");
Signature mySignature = secp256k1.signDetached(myMessage, myKeyPair);
assert sig.getBytes().length == 64;
secp256k1.verify(myMessage, mySignature, myKeyPair) // True
Create an Ed25519
object, create a KeyPair, sign a message and verify it.
Ed25519 ed25519 = new Ed25519();
KeyPair myKeyPair = ed25519.keyPair();
String myMessage = "Hello";
ECDSASignature mySignature = ed25519.signDetached(myMessage, myKeyPair);
ed25519.verify(myMessage, mySignature, myKeyPair) // True
Create a Hasher object, using Java's MessageDigest or using String to specify the algortihm.
Hash a byte array or a String.
Create a Hasher
object, using SHA-256
algorithm, hash a message and encode it to hex.
Hasher sha256 = new Hasher("SHA-256");
Binary mySHA256Digest = sha256.hash("Hello");
String mySHA256HexEncodedBinary = mySHA256Digest.getHex();
Create a Hasher
object, using Keccak-384
algorithm, hash a message and encode it to base58.
Hasher keccak384 = new Hasher("Keccak-384");
String myKeccak384Base58EncodedDigest = keccak384.hash("Hello").getBase58();
Create a Binary object, using byte array.
Create a Binary object, using a hexidecimal value
Create a Binary object, using a base58 encoded value
Create a Binary object, using a base64 encoded value
Get raw byte array of the Binary.
Get hexidecimal representation of the Binary.
Get base58 encoded value of the Binary.
Get base64 encoded value of the Binary.
Create a KeyPair object, using a byte array or a Binary representation of the keys.
Get the public key.
Get the private key.
Create a Signature object, using a byte array.
Create a ECDSASignature object, using byte arrays of the r
, s
and v
components of the signatures.
Create a ECDSASignature object, using byte arrays of the r
and s
components of the signatures (no recId
).
Get the r
component of the ECDSA signature.
Get the s
component of the ECDSA signature.
Get the v
component of the ECDSA signature, that would be the recId
.