Package io.ably.lib.util

Class Crypto

java.lang.Object
io.ably.lib.util.Crypto

public class Crypto extends Object
Contains the properties required to configure the encryption of Message payloads.
  • Field Details

    • DEFAULT_ALGORITHM

      public static final String 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

      public static Crypto.CipherParams getDefaultParams()

      Spec: RSE1

      Returns:
      A Crypto.CipherParams object, 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.CipherParams object, using the default values for any fields not supplied.
    • getDefaultParams

      public static Crypto.CipherParams getDefaultParams(String base64Key)

      Spec: RSE1

      Parameters:
      base64Key - Base64-encoded key
      Returns:
      A Crypto.CipherParams object, using the default values for any fields not supplied.
    • getParams

      public static Crypto.CipherParams getParams(String algorithm, int keyLength)
    • 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

      public static Crypto.CipherParams checkCipherParams(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 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