The Ably.Rest.Crypto object exposes the following public methods:

This call obtains a CipherParams object using the values passed in (which must be a subset of CipherParams fields that at a minimum includes a key), filling in any unspecified fields with default values, and checks that the result is a valid and self-consistent.<span lang=“go”>returns a CipherParams object with fields set to default values. This generates random secret key and initialization vector (iv) values.

You will rarely need to call this yourself, since the client library will handle it for you if you specify cipher params when initializing a channel (as in the example at the top).


The cipher params that you want to specify. It must at a minimum include a key, which should be either a binary () or a base64-encoded String.


On success, the method returns a complete CipherParams object. Failure will raise an exception.


JavaScript v1.2
var cipherParams = Ably.Rest.Crypto.getDefaultParams({key: <key>}); var channelOpts = { cipher: cipherParams }; var channel = rest.channels.get('hat-zip-pub', channelOpts);

Crypto.generateRandomKey(Int keyLength?, callback(ErrorInfo err, Buffer key))

This call obtains a randomly-generated binary key of the specified key length.


Optional Int with the length of key to generate. For AES, this should be either 128 or 256. If unspecified, defaults to 256.
is a function of the form function(err, key) which is called upon completion


JavaScript v1.2
Ably.Rest.Crypto.generateRandomKey(256, function(err, key) { if(err) { console.log("Key generation failed: " + err.toString()); } else { var channel = rest.channels.get('hat-zip-pub', {cipher: {key: key}}); } });

Channel options are used for configuring encryption.


Requests encryption for this channel when not null, and specifies encryption-related parameters (such as algorithm, chaining mode, key length and key). See an exampleType: CipherParams

A CipherParams contains configuration options for a channel cipher, including algorithm, mode, key length and key. Ably client libraries currently support AES with CBC, PKCS#7 with a default key length of 256 bits. All implementations also support AES128.

Individual client libraries may support either instancing a CipherParams directly, using Crypto.getDefaultParams(), or generating one automatically when initializing a channel, as in this example.


A binary () or base64-encoded String containing the secret key used for encryption and decryption
AES The name of the algorithm in the default system provider, or the lower-cased version of it; eg “aes” or “AESType: String
256 The key length in bits of the cipher, either 128 or 256Type: Integer
CBC The cipher modeType: String