Package com.gherynos.libsaltpack
Class Utils
java.lang.Object
com.gherynos.libsaltpack.Utils
Utilities class.
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
baseXblockSize
(String alphabet, int size) Returns the number of required characters to represent in BaseX, for a givenalphabet
,size
characters.static byte[]
baseXdecode
(String data, String alphabet) Decodes the string from BaseX and the givenalphabet
.static String
baseXencode
(byte[] data, int size, String alphabet) Encodes the data in BaseX using the givenalphabet
.static String
baseXencode
(byte[] data, String alphabet) Encodes the data in BaseX using the givenalphabet
.static String
binToHex
(byte[] bin) Binary to hexadecimal encoding.static byte[]
deriveKeyFromPassword
(long keySize, char[] password, byte[] salt, long opsLimit, long memLimit) Wrapper for the `crypto_pwhash` function from `libsodium`.static byte[]
derivePublickey
(byte[] secretkey) Derives the public key from a private key.static void
generateKeypair
(byte[] publickey, byte[] secretkey) Generates an encryption keypair using `libsodium`.static byte[]
generateRandomBytes
(long size) Generates some random bytes using `libsodium`.static void
generateSignKeypair
(byte[] publickey, byte[] secretkey) Generates a signing keypair using `libsodium`.static byte[]
Hexadecial to binary encoding.
-
Method Details
-
generateKeypair
Generates an encryption keypair using `libsodium`.- Parameters:
publickey
- the array that will be populated with the public key.secretkey
- the array that will be populated with the private key.- Throws:
SaltpackException
-
generateSignKeypair
Generates a signing keypair using `libsodium`.- Parameters:
publickey
- the array that will be populated with the public key.secretkey
- the array that will be populated with the private key.- Throws:
SaltpackException
-
derivePublickey
Derives the public key from a private key.- Parameters:
secretkey
- the private key.- Returns:
- the public key.
- Throws:
SaltpackException
-
baseXblockSize
Returns the number of required characters to represent in BaseX, for a givenalphabet
,size
characters.- Parameters:
alphabet
- the alphabet for the BaseX encoding.size
- the size of the data to represent.- Returns:
- the number of characters required to encode
size
characters. - Throws:
SaltpackException
-
baseXencode
Encodes the data in BaseX using the givenalphabet
.- Parameters:
data
- the data to encode.alphabet
- the alphabet for the BaseX encoding.- Returns:
- the encoded string.
- Throws:
SaltpackException
-
baseXencode
Encodes the data in BaseX using the givenalphabet
.- Parameters:
data
- the data to encode.size
- the number of characters to encode fromdata
.alphabet
- the alphabet for the BaseX encoding.- Returns:
- the encoded string.
- Throws:
SaltpackException
-
baseXdecode
Decodes the string from BaseX and the givenalphabet
.- Parameters:
data
- data the string to decode.alphabet
- the alphabet for the BaseX decoding.- Returns:
- the decoded data.
- Throws:
SaltpackException
-
hexToBin
Hexadecial to binary encoding.- Parameters:
hex
- the hexadecimal string.- Returns:
- the binary data.
- Throws:
SaltpackException
-
binToHex
Binary to hexadecimal encoding.- Parameters:
bin
- the binary data.- Returns:
- the hexadecimal string.
- Throws:
SaltpackException
-
generateRandomBytes
Generates some random bytes using `libsodium`.- Parameters:
size
- the amount of bytes to generate.- Returns:
- the random bytes.
- Throws:
SaltpackException
-
deriveKeyFromPassword
public static byte[] deriveKeyFromPassword(long keySize, char[] password, byte[] salt, long opsLimit, long memLimit) throws SaltpackException Wrapper for the `crypto_pwhash` function from `libsodium`.- Parameters:
keySize
- the size of the key.password
- the password used to derive the key.salt
- the salt used to derive the key.opsLimit
- the maximum amount of computations to perform.memLimit
- the maximum amount of RAM that the function will use, in bytes.- Returns:
- the derived key.
- Throws:
SaltpackException
-