Package io.ably.lib.util
Class Crypto
java.lang.Object
io.ably.lib.util.Crypto
Contains the properties required to configure the encryption of
Message
payloads.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static interface
Internal; a cipher used to decrypt plaintext from ciphertext, for a channel.static interface
Internal; a cipher used to encrypt plaintext to ciphertext, for a channel. -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Crypto.CipherParams
checkCipherParams
(Object cipherParams) Internal; if `cipherParams` is null returns default params otherwise check if params valid and returns themcreateChannelDecipher
(Crypto.CipherParams cipherParams) Internal; get a decrypting cipher instance based on the given channel options.createChannelEncipher
(Crypto.CipherParams cipherParams) Internal; get an encrypting cipher instance based on the given channel options.static byte[]
Generates a random key to be used in the encryption of the channel.static byte[]
generateRandomKey
(int keyLength) Generates a random key to be used in the encryption of the channel.static Param
Returns a "request_id" query param, based on a sequence of 9 random bytes which have been base64 encoded.static Crypto.CipherParams
Spec: RSE1static Crypto.CipherParams
getDefaultParams
(byte[] key) Spec: RSE1static Crypto.CipherParams
getDefaultParams
(String base64Key) Spec: RSE1static Crypto.CipherParams
static Crypto.CipherParams
static Crypto.CipherParams
static String
-
Field Details
-
DEFAULT_ALGORITHM
- See Also:
-
DEFAULT_KEYLENGTH
public static final int DEFAULT_KEYLENGTH -
DEFAULT_BLOCKLENGTH
public static final int DEFAULT_BLOCKLENGTH- See Also:
-
-
Constructor Details
-
Crypto
public Crypto()
-
-
Method Details
-
getDefaultParams
Spec: RSE1
- Returns:
- A
Crypto.CipherParams
object, using the default values for all fields.
-
getDefaultParams
Spec: RSE1
- Parameters:
-
key
- client-provided key - Returns:
- A
Crypto.CipherParams
object, using the default values for any fields not supplied.
-
getDefaultParams
Spec: RSE1
- Parameters:
-
base64Key
- Base64-encoded key - Returns:
- A
Crypto.CipherParams
object, using the default values for any fields not supplied.
-
getParams
-
getParams
public static Crypto.CipherParams getParams(String algorithm, byte[] key) throws NoSuchAlgorithmException - Throws:
NoSuchAlgorithmException
-
getParams
public static Crypto.CipherParams getParams(String algorithm, byte[] key, byte[] iv) throws NoSuchAlgorithmException - Throws:
NoSuchAlgorithmException
-
generateRandomKey
public static byte[] generateRandomKey(int keyLength) Generates a random key to be used in the encryption of the channel. If the language cryptographic randomness primitives are blocking or async, a callback is used. The callback returns a generated binary key.Spec: RSE2
- Parameters:
-
keyLength
- The length of the key, in bits, to be generated. If not specified, this is equal to the default keyLength of the default algorithm: for AES this is 256 bits. - Returns:
- The key as a binary, in a byte array.
-
generateRandomKey
public static byte[] generateRandomKey()Generates a random key to be used in the encryption of the channel. If the language cryptographic randomness primitives are blocking or async, a callback is used. The callback returns a generated binary key.Spec: RSE2
- Returns:
- The key as a binary, in a byte array.
-
createChannelEncipher
public static Crypto.EncryptingChannelCipher createChannelEncipher(Crypto.CipherParams cipherParams) throws AblyException Internal; get an encrypting cipher instance based on the given channel options.- Throws:
AblyException
-
createChannelDecipher
public static Crypto.DecryptingChannelCipher createChannelDecipher(Crypto.CipherParams cipherParams) throws AblyException Internal; get a decrypting cipher instance based on the given channel options.- Throws:
AblyException
-
checkCipherParams
Internal; if `cipherParams` is null returns default params otherwise check if params valid and returns them- Throws:
AblyException
-
getRandomId
-
generateRandomRequestId
Returns a "request_id" query param, based on a sequence of 9 random bytes which have been base64 encoded. Spec: RSC7c
-