java.lang.Object
tech.deplant.java4ever.binding.Crypto
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
static class
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionchacha20
(@NonNull Context context, @NonNull String data, @NonNull String key, @NonNull String nonce) Performs symmetric `chacha20` encryption.convertPublicKeyToTonSafeFormat
(@NonNull Context context, @NonNull String publicKey) Converts public key to ton safe_formatcreateEncryptionBox
(@NonNull Context context, @NonNull Crypto.EncryptionAlgorithm algorithm) Creates encryption box with specified algorithmencryptionBoxDecrypt
(@NonNull Context context, @NonNull Integer encryptionBox, @NonNull String data) Decrypts data using given encryption box Note.encryptionBoxEncrypt
(@NonNull Context context, @NonNull Integer encryptionBox, @NonNull String data) Encrypts data using given encryption box Note.encryptionBoxGetInfo
(@NonNull Context context, @NonNull Integer encryptionBox) Queries info from the given encryption boxInteger factorizationgenerateRandomBytes
(@NonNull Context context, @NonNull Number length) Generates random byte array of the specified length and returns it in `base64` formatstatic CompletableFuture<Crypto.KeyPair>
generateRandomSignKeys
(@NonNull Context context) Generates random ed25519 key pair.getSigningBox
(@NonNull Context context, @NonNull String publicKey, @NonNull String secretKey) Creates a default signing box implementation.hdkeyDeriveFromXprv
(@NonNull Context context, @NonNull String xprv, @NonNull Number childIndex, @NonNull Boolean hardened) Returns extended private key derived from the specified extended private key and child indexhdkeyDeriveFromXprvPath
(@NonNull Context context, @NonNull String xprv, @NonNull String path) Derives the extended private key from the specified key and pathhdkeyPublicFromXprv
(@NonNull Context context, @NonNull String xprv) Extracts the public key from the serialized extended private keyhdkeySecretFromXprv
(@NonNull Context context, @NonNull String xprv) Extracts the private key from the serialized extended private keyhdkeyXprvFromMnemonic
(@NonNull Context context, @NonNull String phrase, Number dictionary, Number wordCount) Generates an extended master private key that will be the root for all the derived keysstatic CompletableFuture<Crypto.KeyPair>
mnemonicDeriveSignKeys
(@NonNull Context context, @NonNull String phrase, String path, Number dictionary, Number wordCount) Derives a key pair for signing from the seed phrasemnemonicFromEntropy
(@NonNull Context context, @NonNull String entropy, Number dictionary, Number wordCount) Generates mnemonic from pre-generated entropymnemonicFromRandom
(@NonNull Context context, Number dictionary, Number wordCount) Generates a random mnemonicmnemonicVerify
(@NonNull Context context, @NonNull String phrase, Number dictionary, Number wordCount) Validates a mnemonic phrasemnemonicWords
(@NonNull Context context, Number dictionary) Prints the list of words from the specified dictionarymodularPower
(@NonNull Context context, @NonNull String base, @NonNull String exponent, @NonNull String modulus) Modular exponentiationnaclBox
(@NonNull Context context, @NonNull String decrypted, @NonNull String nonce, @NonNull String theirPublic, @NonNull String secretKey) Public key authenticated encryptionstatic CompletableFuture<Crypto.KeyPair>
naclBoxKeypair
(@NonNull Context context) Generates a random NaCl key pairstatic CompletableFuture<Crypto.KeyPair>
naclBoxKeypairFromSecretKey
(@NonNull Context context, @NonNull String secretKey) Generates key pair from a secret keynaclBoxOpen
(@NonNull Context context, @NonNull String encrypted, @NonNull String nonce, @NonNull String theirPublic, @NonNull String secretKey) Decrypt and verify the cipher text using the receivers secret key, the senders public key, and the nonce.naclSecretBox
(@NonNull Context context, @NonNull String decrypted, @NonNull String nonce, @NonNull String key) Encrypt and authenticate message using nonce and secret key.naclSecretBoxOpen
(@NonNull Context context, @NonNull String encrypted, @NonNull String nonce, @NonNull String key) Decrypts and verifies cipher text using `nonce` and secret `key`.Signs data using the signer's secret key.naclSignDetached
(@NonNull Context context, @NonNull String unsigned, @NonNull String secretKey) Signs the message using the secret key and returns a signature.naclSignDetachedVerify
(@NonNull Context context, @NonNull String unsigned, @NonNull String signature, @NonNull String publicKey) Verifies the signature with public key and `unsigned` data.static CompletableFuture<Crypto.KeyPair>
naclSignKeypairFromSecretKey
(@NonNull Context context, @NonNull String secretKey) Generates a key pair for signing from the secret keynaclSignOpen
(@NonNull Context context, @NonNull String signed, @NonNull String publicKey) Verifies the signature and returns the unsigned messagestatic CompletableFuture<Void>
removeEncryptionBox
(@NonNull Context context, @NonNull Integer handle) Removes encryption box from SDKstatic CompletableFuture<Void>
removeSigningBox
(@NonNull Context context, @NonNull Integer handle) Removes signing box from SDK.scrypt
(@NonNull Context context, @NonNull String password, @NonNull String salt, @NonNull Number logN, @NonNull Number r, @NonNull Number p, @NonNull Number dkLen) Perform `scrypt` encryptionstatic CompletableFuture<Crypto.ResultOfHash>
Calculates SHA256 hash of the specified data.static CompletableFuture<Crypto.ResultOfHash>
Calculates SHA512 hash of the specified data.static CompletableFuture<Crypto.ResultOfSign>
sign
(@NonNull Context context, @NonNull String unsigned, @NonNull Crypto.KeyPair keys) Signs a data using the provided keys.signingBoxGetPublicKey
(@NonNull Context context, @NonNull Integer handle) Returns public key of signing key pair.signingBoxSign
(@NonNull Context context, @NonNull Integer signingBox, @NonNull String unsigned) Returns signed user data.Calculates CRC16 using TON algorithm.verifySignature
(@NonNull Context context, @NonNull String signed, @NonNull String publicKey) Verifies signed data using the provided public key.
-
Constructor Details
-
Crypto
public Crypto()
-
-
Method Details
-
factorize
public static CompletableFuture<Crypto.ResultOfFactorize> factorize(@NonNull @NonNull Context context, @NonNull @NonNull String composite) Integer factorization- Parameters:
composite
- Hexadecimal representation of u64 composite number.
-
modularPower
public static CompletableFuture<Crypto.ResultOfModularPower> modularPower(@NonNull @NonNull Context context, @NonNull @NonNull String base, @NonNull @NonNull String exponent, @NonNull @NonNull String modulus) Modular exponentiation- Parameters:
base
- `base` argument of calculation.exponent
- `exponent` argument of calculation.modulus
- `modulus` argument of calculation.
-
tonCrc16
public static CompletableFuture<Crypto.ResultOfTonCrc16> tonCrc16(@NonNull @NonNull Context context, @NonNull @NonNull String data) Calculates CRC16 using TON algorithm.- Parameters:
data
- Input data for CRC calculation. Encoded with `base64`.
-
generateRandomBytes
public static CompletableFuture<Crypto.ResultOfGenerateRandomBytes> generateRandomBytes(@NonNull @NonNull Context context, @NonNull @NonNull Number length) Generates random byte array of the specified length and returns it in `base64` format- Parameters:
length
- Size of random byte array.
-
convertPublicKeyToTonSafeFormat
public static CompletableFuture<Crypto.ResultOfConvertPublicKeyToTonSafeFormat> convertPublicKeyToTonSafeFormat(@NonNull @NonNull Context context, @NonNull @NonNull String publicKey) Converts public key to ton safe_format- Parameters:
publicKey
- Public key - 64 symbols hex string
-
generateRandomSignKeys
public static CompletableFuture<Crypto.KeyPair> generateRandomSignKeys(@NonNull @NonNull Context context) Generates random ed25519 key pair. -
sign
public static CompletableFuture<Crypto.ResultOfSign> sign(@NonNull @NonNull Context context, @NonNull @NonNull String unsigned, @NonNull @NonNull Crypto.KeyPair keys) Signs a data using the provided keys.- Parameters:
unsigned
- Data that must be signed encoded in `base64`.keys
- Sign keys.
-
verifySignature
public static CompletableFuture<Crypto.ResultOfVerifySignature> verifySignature(@NonNull @NonNull Context context, @NonNull @NonNull String signed, @NonNull @NonNull String publicKey) Verifies signed data using the provided public key. Raises error if verification is failed.- Parameters:
signed
- Signed data that must be verified encoded in `base64`.publicKey
- Signer's public key - 64 symbols hex string
-
sha256
public static CompletableFuture<Crypto.ResultOfHash> sha256(@NonNull @NonNull Context context, @NonNull @NonNull String data) Calculates SHA256 hash of the specified data.- Parameters:
data
- Input data for hash calculation. Encoded with `base64`.
-
sha512
public static CompletableFuture<Crypto.ResultOfHash> sha512(@NonNull @NonNull Context context, @NonNull @NonNull String data) Calculates SHA512 hash of the specified data.- Parameters:
data
- Input data for hash calculation. Encoded with `base64`.
-
scrypt
public static CompletableFuture<Crypto.ResultOfScrypt> scrypt(@NonNull @NonNull Context context, @NonNull @NonNull String password, @NonNull @NonNull String salt, @NonNull @NonNull Number logN, @NonNull @NonNull Number r, @NonNull @NonNull Number p, @NonNull @NonNull Number dkLen) Perform `scrypt` encryption- Parameters:
password
- The password bytes to be hashed. Must be encoded with `base64`.salt
- Salt bytes that modify the hash to protect against Rainbow table attacks. Must be encoded with `base64`.logN
- CPU/memory cost parameterr
- The block size parameter, which fine-tunes sequential memory read size and performance.p
- Parallelization parameter.dkLen
- Intended output length in octets of the derived key.
-
naclSignKeypairFromSecretKey
public static CompletableFuture<Crypto.KeyPair> naclSignKeypairFromSecretKey(@NonNull @NonNull Context context, @NonNull @NonNull String secretKey) Generates a key pair for signing from the secret key- Parameters:
secretKey
- Secret key - unprefixed 0-padded to 64 symbols hex string
-
naclSign
public static CompletableFuture<Crypto.ResultOfNaclSign> naclSign(@NonNull @NonNull Context context, @NonNull @NonNull String unsigned, @NonNull @NonNull String secretKey) Signs data using the signer's secret key.- Parameters:
unsigned
- Data that must be signed encoded in `base64`.secretKey
- Signer's secret key - unprefixed 0-padded to 128 symbols hex string (concatenation of 64 symbols secret and 64 symbols public keys). See `nacl_sign_keypair_from_secret_key`.
-
naclSignOpen
public static CompletableFuture<Crypto.ResultOfNaclSignOpen> naclSignOpen(@NonNull @NonNull Context context, @NonNull @NonNull String signed, @NonNull @NonNull String publicKey) Verifies the signature and returns the unsigned message- Parameters:
signed
- Signed data that must be unsigned. Encoded with `base64`.publicKey
- Signer's public key - unprefixed 0-padded to 64 symbols hex string
-
naclSignDetached
public static CompletableFuture<Crypto.ResultOfNaclSignDetached> naclSignDetached(@NonNull @NonNull Context context, @NonNull @NonNull String unsigned, @NonNull @NonNull String secretKey) Signs the message using the secret key and returns a signature.- Parameters:
unsigned
- Data that must be signed encoded in `base64`.secretKey
- Signer's secret key - unprefixed 0-padded to 128 symbols hex string (concatenation of 64 symbols secret and 64 symbols public keys). See `nacl_sign_keypair_from_secret_key`.
-
naclSignDetachedVerify
public static CompletableFuture<Crypto.ResultOfNaclSignDetachedVerify> naclSignDetachedVerify(@NonNull @NonNull Context context, @NonNull @NonNull String unsigned, @NonNull @NonNull String signature, @NonNull @NonNull String publicKey) Verifies the signature with public key and `unsigned` data.- Parameters:
unsigned
- Unsigned data that must be verified. Encoded with `base64`.signature
- Signature that must be verified. Encoded with `hex`.publicKey
- Signer's public key - unprefixed 0-padded to 64 symbols hex string.
-
naclBoxKeypair
Generates a random NaCl key pair -
naclBoxKeypairFromSecretKey
public static CompletableFuture<Crypto.KeyPair> naclBoxKeypairFromSecretKey(@NonNull @NonNull Context context, @NonNull @NonNull String secretKey) Generates key pair from a secret key- Parameters:
secretKey
- Secret key - unprefixed 0-padded to 64 symbols hex string
-
naclBox
public static CompletableFuture<Crypto.ResultOfNaclBox> naclBox(@NonNull @NonNull Context context, @NonNull @NonNull String decrypted, @NonNull @NonNull String nonce, @NonNull @NonNull String theirPublic, @NonNull @NonNull String secretKey) Public key authenticated encryption- Parameters:
decrypted
- Data that must be encrypted encoded in `base64`.nonce
- Nonce, encoded in `hex`theirPublic
- Receiver's public key - unprefixed 0-padded to 64 symbols hex stringsecretKey
- Sender's private key - unprefixed 0-padded to 64 symbols hex string
-
naclBoxOpen
public static CompletableFuture<Crypto.ResultOfNaclBoxOpen> naclBoxOpen(@NonNull @NonNull Context context, @NonNull @NonNull String encrypted, @NonNull @NonNull String nonce, @NonNull @NonNull String theirPublic, @NonNull @NonNull String secretKey) Decrypt and verify the cipher text using the receivers secret key, the senders public key, and the nonce.- Parameters:
encrypted
- Data that must be decrypted. Encoded with `base64`.nonce
-theirPublic
- Sender's public key - unprefixed 0-padded to 64 symbols hex stringsecretKey
- Receiver's private key - unprefixed 0-padded to 64 symbols hex string
-
naclSecretBox
public static CompletableFuture<Crypto.ResultOfNaclBox> naclSecretBox(@NonNull @NonNull Context context, @NonNull @NonNull String decrypted, @NonNull @NonNull String nonce, @NonNull @NonNull String key) Encrypt and authenticate message using nonce and secret key.- Parameters:
decrypted
- Data that must be encrypted. Encoded with `base64`.nonce
- Nonce in `hex`key
- Secret key - unprefixed 0-padded to 64 symbols hex string
-
naclSecretBoxOpen
public static CompletableFuture<Crypto.ResultOfNaclBoxOpen> naclSecretBoxOpen(@NonNull @NonNull Context context, @NonNull @NonNull String encrypted, @NonNull @NonNull String nonce, @NonNull @NonNull String key) Decrypts and verifies cipher text using `nonce` and secret `key`.- Parameters:
encrypted
- Data that must be decrypted. Encoded with `base64`.nonce
- Nonce in `hex`key
- Public key - unprefixed 0-padded to 64 symbols hex string
-
mnemonicWords
public static CompletableFuture<Crypto.ResultOfMnemonicWords> mnemonicWords(@NonNull @NonNull Context context, Number dictionary) Prints the list of words from the specified dictionary- Parameters:
dictionary
- Dictionary identifier
-
mnemonicFromRandom
public static CompletableFuture<Crypto.ResultOfMnemonicFromRandom> mnemonicFromRandom(@NonNull @NonNull Context context, Number dictionary, Number wordCount) Generates a random mnemonic- Parameters:
dictionary
- Dictionary identifierwordCount
- Mnemonic word count
-
mnemonicFromEntropy
public static CompletableFuture<Crypto.ResultOfMnemonicFromEntropy> mnemonicFromEntropy(@NonNull @NonNull Context context, @NonNull @NonNull String entropy, Number dictionary, Number wordCount) Generates mnemonic from pre-generated entropy- Parameters:
entropy
- Entropy bytes. Hex encoded.dictionary
- Dictionary identifierwordCount
- Mnemonic word count
-
mnemonicVerify
public static CompletableFuture<Crypto.ResultOfMnemonicVerify> mnemonicVerify(@NonNull @NonNull Context context, @NonNull @NonNull String phrase, Number dictionary, Number wordCount) Validates a mnemonic phrase- Parameters:
phrase
- Phrasedictionary
- Dictionary identifierwordCount
- Word count
-
mnemonicDeriveSignKeys
public static CompletableFuture<Crypto.KeyPair> mnemonicDeriveSignKeys(@NonNull @NonNull Context context, @NonNull @NonNull String phrase, String path, Number dictionary, Number wordCount) Derives a key pair for signing from the seed phrase- Parameters:
phrase
- Phrasepath
- Derivation path, for instance "m/44'/396'/0'/0/0"dictionary
- Dictionary identifierwordCount
- Word count
-
hdkeyXprvFromMnemonic
public static CompletableFuture<Crypto.ResultOfHDKeyXPrvFromMnemonic> hdkeyXprvFromMnemonic(@NonNull @NonNull Context context, @NonNull @NonNull String phrase, Number dictionary, Number wordCount) Generates an extended master private key that will be the root for all the derived keys- Parameters:
phrase
- String with seed phrasedictionary
- Dictionary identifierwordCount
- Mnemonic word count
-
hdkeyDeriveFromXprv
public static CompletableFuture<Crypto.ResultOfHDKeyDeriveFromXPrv> hdkeyDeriveFromXprv(@NonNull @NonNull Context context, @NonNull @NonNull String xprv, @NonNull @NonNull Number childIndex, @NonNull @NonNull Boolean hardened) Returns extended private key derived from the specified extended private key and child index- Parameters:
xprv
- Serialized extended private keychildIndex
- Child index (see BIP-0032)hardened
- Indicates the derivation of hardened/not-hardened key (see BIP-0032)
-
hdkeyDeriveFromXprvPath
public static CompletableFuture<Crypto.ResultOfHDKeyDeriveFromXPrvPath> hdkeyDeriveFromXprvPath(@NonNull @NonNull Context context, @NonNull @NonNull String xprv, @NonNull @NonNull String path) Derives the extended private key from the specified key and path- Parameters:
xprv
- Serialized extended private keypath
- Derivation path, for instance "m/44'/396'/0'/0/0"
-
hdkeySecretFromXprv
public static CompletableFuture<Crypto.ResultOfHDKeySecretFromXPrv> hdkeySecretFromXprv(@NonNull @NonNull Context context, @NonNull @NonNull String xprv) Extracts the private key from the serialized extended private key- Parameters:
xprv
- Serialized extended private key
-
hdkeyPublicFromXprv
public static CompletableFuture<Crypto.ResultOfHDKeyPublicFromXPrv> hdkeyPublicFromXprv(@NonNull @NonNull Context context, @NonNull @NonNull String xprv) Extracts the public key from the serialized extended private key- Parameters:
xprv
- Serialized extended private key
-
chacha20
public static CompletableFuture<Crypto.ResultOfChaCha20> chacha20(@NonNull @NonNull Context context, @NonNull @NonNull String data, @NonNull @NonNull String key, @NonNull @NonNull String nonce) Performs symmetric `chacha20` encryption.- Parameters:
data
- Source data to be encrypted or decrypted. Must be encoded with `base64`.key
- 256-bit key. Must be encoded with `hex`.nonce
- 96-bit nonce. Must be encoded with `hex`.
-
getSigningBox
public static CompletableFuture<Crypto.RegisteredSigningBox> getSigningBox(@NonNull @NonNull Context context, @NonNull @NonNull String publicKey, @NonNull @NonNull String secretKey) Creates a default signing box implementation.- Parameters:
publicKey
- Public key - 64 symbols hex stringsecretKey
- Private key - u64 symbols hex string
-
signingBoxGetPublicKey
public static CompletableFuture<Crypto.ResultOfSigningBoxGetPublicKey> signingBoxGetPublicKey(@NonNull @NonNull Context context, @NonNull @NonNull Integer handle) Returns public key of signing key pair.- Parameters:
handle
- Handle of the signing box.
-
signingBoxSign
public static CompletableFuture<Crypto.ResultOfSigningBoxSign> signingBoxSign(@NonNull @NonNull Context context, @NonNull @NonNull Integer signingBox, @NonNull @NonNull String unsigned) Returns signed user data.- Parameters:
signingBox
- Signing Box handle.unsigned
- Unsigned user data. Must be encoded with `base64`.
-
removeSigningBox
public static CompletableFuture<Void> removeSigningBox(@NonNull @NonNull Context context, @NonNull @NonNull Integer handle) Removes signing box from SDK.- Parameters:
handle
- Handle of the signing box.
-
removeEncryptionBox
public static CompletableFuture<Void> removeEncryptionBox(@NonNull @NonNull Context context, @NonNull @NonNull Integer handle) Removes encryption box from SDK- Parameters:
handle
- Handle of the encryption box
-
encryptionBoxGetInfo
public static CompletableFuture<Crypto.ResultOfEncryptionBoxGetInfo> encryptionBoxGetInfo(@NonNull @NonNull Context context, @NonNull @NonNull Integer encryptionBox) Queries info from the given encryption box- Parameters:
encryptionBox
- Encryption box handle
-
encryptionBoxEncrypt
public static CompletableFuture<Crypto.ResultOfEncryptionBoxEncrypt> encryptionBoxEncrypt(@NonNull @NonNull Context context, @NonNull @NonNull Integer encryptionBox, @NonNull @NonNull String data) Encrypts data using given encryption box Note.- Parameters:
encryptionBox
- Encryption box handledata
- Data to be encrypted, encoded in Base64
-
encryptionBoxDecrypt
public static CompletableFuture<Crypto.ResultOfEncryptionBoxDecrypt> encryptionBoxDecrypt(@NonNull @NonNull Context context, @NonNull @NonNull Integer encryptionBox, @NonNull @NonNull String data) Decrypts data using given encryption box Note.- Parameters:
encryptionBox
- Encryption box handledata
- Data to be decrypted, encoded in Base64
-
createEncryptionBox
public static CompletableFuture<Crypto.RegisteredEncryptionBox> createEncryptionBox(@NonNull @NonNull Context context, @NonNull @NonNull Crypto.EncryptionAlgorithm algorithm) Creates encryption box with specified algorithm- Parameters:
algorithm
- Encryption algorithm specifier including cipher parameters (key, IV, etc)
-