Package io.ably.lib.util
Class Crypto
- java.lang.Object
-
- io.ably.lib.util.Crypto
-
public class Crypto extends java.lang.ObjectContains the properties required to configure the encryption ofMessagepayloads.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCrypto.CipherParamsstatic interfaceCrypto.DecryptingChannelCipherInternal; a cipher used to decrypt plaintext from ciphertext, for a channel.static interfaceCrypto.EncryptingChannelCipherInternal; a cipher used to encrypt plaintext to ciphertext, for a channel.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_ALGORITHMstatic intDEFAULT_BLOCKLENGTHstatic intDEFAULT_KEYLENGTH
-
Constructor Summary
Constructors Constructor Description Crypto()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Crypto.CipherParamscheckCipherParams(java.lang.Object cipherParams)Internal; if `cipherParams` is null returns default params otherwise check if params valid and returns themstatic Crypto.DecryptingChannelCiphercreateChannelDecipher(Crypto.CipherParams cipherParams)Internal; get a decrypting cipher instance based on the given channel options.static Crypto.EncryptingChannelCiphercreateChannelEncipher(Crypto.CipherParams cipherParams)Internal; get an encrypting cipher instance based on the given channel options.static byte[]generateRandomKey()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 ParamgenerateRandomRequestId()Returns a "request_id" query param, based on a sequence of 9 random bytes which have been base64 encoded.static Crypto.CipherParamsgetDefaultParams()Spec: RSE1static Crypto.CipherParamsgetDefaultParams(byte[] key)Spec: RSE1static Crypto.CipherParamsgetDefaultParams(java.lang.String base64Key)Spec: RSE1static Crypto.CipherParamsgetParams(java.lang.String algorithm, byte[] key)static Crypto.CipherParamsgetParams(java.lang.String algorithm, byte[] key, byte[] iv)static Crypto.CipherParamsgetParams(java.lang.String algorithm, int keyLength)static java.lang.StringgetRandomId()
-
-
-
Field Detail
-
DEFAULT_ALGORITHM
public static final java.lang.String DEFAULT_ALGORITHM
- See Also:
- Constant Field Values
-
DEFAULT_KEYLENGTH
public static final int DEFAULT_KEYLENGTH
-
DEFAULT_BLOCKLENGTH
public static final int DEFAULT_BLOCKLENGTH
- See Also:
- Constant Field Values
-
-
Method Detail
-
getDefaultParams
public static Crypto.CipherParams getDefaultParams()
Spec: RSE1
- Returns:
- A
Crypto.CipherParamsobject, using the default values for all fields.
-
getDefaultParams
public static Crypto.CipherParams getDefaultParams(byte[] key)
Spec: RSE1
- Parameters:
key- client-provided key- Returns:
- A
Crypto.CipherParamsobject, using the default values for any fields not supplied.
-
getDefaultParams
public static Crypto.CipherParams getDefaultParams(java.lang.String base64Key)
Spec: RSE1
- Parameters:
base64Key- Base64-encoded key- Returns:
- A
Crypto.CipherParamsobject, using the default values for any fields not supplied.
-
getParams
public static Crypto.CipherParams getParams(java.lang.String algorithm, int keyLength)
-
getParams
public static Crypto.CipherParams getParams(java.lang.String algorithm, byte[] key) throws java.security.NoSuchAlgorithmException
- Throws:
java.security.NoSuchAlgorithmException
-
getParams
public static Crypto.CipherParams getParams(java.lang.String algorithm, byte[] key, byte[] iv) throws java.security.NoSuchAlgorithmException
- Throws:
java.security.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
public static Crypto.CipherParams checkCipherParams(java.lang.Object cipherParams) throws AblyException
Internal; if `cipherParams` is null returns default params otherwise check if params valid and returns them- Throws:
AblyException
-
getRandomId
public static java.lang.String getRandomId()
-
generateRandomRequestId
public static Param generateRandomRequestId()
Returns a "request_id" query param, based on a sequence of 9 random bytes which have been base64 encoded. Spec: RSC7c
-
-