Package org.drasyl.crypto.sodium
Class DrasylSodiumWrapper
java.lang.Object
org.drasyl.crypto.sodium.DrasylSodiumWrapper
Simple wrapper class that make native class easier.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final short
static final short
static final short
static final short
static final short
static final short
static final short
static final short
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
convertPublicKeyEd25519ToCurve25519
(byte[] curve, byte[] ed) Converts a public ed25519 key to a public curve25519 key.boolean
convertSecretKeyEd25519ToCurve25519
(byte[] curve, byte[] ed) Converts a secret ed25519 key to a secret curve25519 key.byte[]
cryptoAeadXChaCha20Poly1305IetfDecrypt
(byte[] c, byte[] ad, byte[] nPub, byte[] k) This function decrypts the given ciphertextc
.byte[]
cryptoAeadXChaCha20Poly1305IetfEncrypt
(byte[] m, byte[] ad, byte[] nPub, byte[] k) This function encrypts the given messagem
.cryptoKxClientSessionKeys
(byte[] clientPk, byte[] clientSk, byte[] serverPk) This function computes a pair of shared keys (rx and tx) using the client's public key clientPk, the client's secret key clientSk and the server's public key serverPk.cryptoKxServerSessionKeys
(byte[] serverPk, byte[] serverSk, byte[] clientPk) This function computes a pair of shared keys (rx and tx) using the client's public key clientPk, the server's secret key serverSk and the server's public key serverPk.byte[]
cryptoSignDetached
(byte[] message, byte[] secretKey) Returns a signature for a message.boolean
cryptoSignKeypair
(byte[] publicKey, byte[] secretKey) Generate a signing keypair (ed25519).boolean
cryptoSignVerifyDetached
(byte[] signature, byte[] message, byte[] publicKey) Verifies thatsignature
is valid for themessage
.boolean
successful
(int res) Evaluates the return value of a native sodium function call.
-
Field Details
-
ED25519_PUBLICKEYBYTES
public static final short ED25519_PUBLICKEYBYTES- See Also:
-
ED25519_SECRETKEYBYTES
public static final short ED25519_SECRETKEYBYTES- See Also:
-
ED25519_BYTES
public static final short ED25519_BYTES- See Also:
-
CURVE25519_PUBLICKEYBYTES
public static final short CURVE25519_PUBLICKEYBYTES- See Also:
-
CURVE25519_SECRETKEYBYTES
public static final short CURVE25519_SECRETKEYBYTES- See Also:
-
SESSIONKEYBYTES
public static final short SESSIONKEYBYTES- See Also:
-
XCHACHA20POLY1305_IETF_ABYTES
public static final short XCHACHA20POLY1305_IETF_ABYTES- See Also:
-
XCHACHA20POLY1305_IETF_NPUBBYTES
public static final short XCHACHA20POLY1305_IETF_NPUBBYTES- See Also:
-
-
Constructor Details
-
DrasylSodiumWrapper
-
-
Method Details
-
cryptoSignKeypair
public boolean cryptoSignKeypair(byte[] publicKey, byte[] secretKey) Generate a signing keypair (ed25519).- Parameters:
publicKey
- Public key.secretKey
- Secret key.- Returns:
- True if successful.
-
convertPublicKeyEd25519ToCurve25519
public boolean convertPublicKeyEd25519ToCurve25519(byte[] curve, byte[] ed) Converts a public ed25519 key to a public curve25519 key.- Parameters:
curve
- The array in which the generated key will be placed.ed
- The public key in ed25519.- Returns:
- Return true if the conversion was successful.
-
convertSecretKeyEd25519ToCurve25519
public boolean convertSecretKeyEd25519ToCurve25519(byte[] curve, byte[] ed) Converts a secret ed25519 key to a secret curve25519 key.- Parameters:
curve
- The array in which the generated key will be placed.ed
- The secret key in ed25519.- Returns:
- Return true if the conversion was successful.
-
cryptoKxServerSessionKeys
public SessionPair cryptoKxServerSessionKeys(byte[] serverPk, byte[] serverSk, byte[] clientPk) throws CryptoException This function computes a pair of shared keys (rx and tx) using the client's public key clientPk, the server's secret key serverSk and the server's public key serverPk.- Parameters:
serverPk
- Server public key of sizeCURVE25519_PUBLICKEYBYTES
.serverSk
- Server secret key of sizeCURVE25519_SECRETKEYBYTES
.clientPk
- Client public key of sizeCURVE25519_PUBLICKEYBYTES
.- Returns:
- True if successful or false if the client public key is wrong.
- Throws:
CryptoException
-
cryptoKxClientSessionKeys
public SessionPair cryptoKxClientSessionKeys(byte[] clientPk, byte[] clientSk, byte[] serverPk) throws CryptoException This function computes a pair of shared keys (rx and tx) using the client's public key clientPk, the client's secret key clientSk and the server's public key serverPk.- Parameters:
clientPk
- Client public key of sizeCURVE25519_PUBLICKEYBYTES
.clientSk
- Client secret key of sizeCURVE25519_SECRETKEYBYTES
.serverPk
- Server public key of sizeCURVE25519_PUBLICKEYBYTES
.- Returns:
- True if successful or false if the server public key is wrong.
- Throws:
CryptoException
-
cryptoAeadXChaCha20Poly1305IetfEncrypt
public byte[] cryptoAeadXChaCha20Poly1305IetfEncrypt(byte[] m, byte[] ad, byte[] nPub, byte[] k) This function encrypts the given messagem
.- Parameters:
m
- the message as byte arrayad
- the authentication tagnPub
- the public noncek
- the key for encryption- Returns:
- the encrypted message or
null
on failure
-
cryptoAeadXChaCha20Poly1305IetfDecrypt
public byte[] cryptoAeadXChaCha20Poly1305IetfDecrypt(byte[] c, byte[] ad, byte[] nPub, byte[] k) This function decrypts the given ciphertextc
.- Parameters:
c
- the cipher textad
- the authentication tagnPub
- the public noncek
- the key for encryption- Returns:
- the decrypted message or
null
on failure
-
cryptoSignDetached
public byte[] cryptoSignDetached(byte[] message, byte[] secretKey) Returns a signature for a message. This does not prepend the signature to the message.- Parameters:
message
- The message to sign.secretKey
- The secret key.- Returns:
- the signature or
null
on failure
-
cryptoSignVerifyDetached
public boolean cryptoSignVerifyDetached(byte[] signature, byte[] message, byte[] publicKey) Verifies thatsignature
is valid for themessage
.- Parameters:
signature
- The signature.message
- The message.publicKey
- The public key that signed the message.- Returns:
- Returns true if the signature is valid for the message.
-
successful
public boolean successful(int res) Evaluates the return value of a native sodium function call.- Parameters:
res
- the result of the function call- Returns:
- true if call was successful, otherwise false
-
getSodium
-