View Source StickerClient.Crypto (stickerclient v0.2.0)

StickerClient.Crypto provides cryptographic utilities required when interacting with the Signal Sticker API.

Link to this section Summary

Functions

Attempts to decrypt the given binary by first deriving AES and HMAC keys from the pack key, then decrypting the content using the derived keys

Attempts to decrypt the given binary using the provided AES key for encryption and HMAC key for integrity

Derives the AES (encryption) and HMAC (integrity) keys from the provided pack key.

Link to this section Functions

Link to this function

decrypt_content(encrypted_content, key)

View Source
@spec decrypt_content(binary(), String.t()) ::
  {:ok, binary()} | {:error, StickerClient.Exception.t()}

Attempts to decrypt the given binary by first deriving AES and HMAC keys from the pack key, then decrypting the content using the derived keys

This method is a convenience to avoid a call to StickerClient.Crypto.derive_keys/1 yourself, but is effectively the same. If decrypting multiple binaries which are all from the same pack, consider instead deriving the keys once and passing those keys to StickerClient.Crypto.decrypt_content/3 instead.

Link to this function

decrypt_content(encrypted_content, aes_key, hmac_key)

View Source
@spec decrypt_content(binary(), String.t(), String.t()) ::
  {:ok, binary()} | {:error, StickerClient.Exception.t()}

Attempts to decrypt the given binary using the provided AES key for encryption and HMAC key for integrity

This method should be used alongside StickerClient.Crypto.derive_keys/1 to derive the keys once, then decrypting and validating all content by providing those keys, as well as the encrypted content, to this method.

@spec derive_keys(String.t()) ::
  {:ok, {binary(), binary()}} | {:error, StickerClient.Exception.t()}

Derives the AES (encryption) and HMAC (integrity) keys from the provided pack key.

Typically not called directly as part of pack downloading or uploading, this function allows for the keys to be derived outside of the crypto operations on a per element (manifest|sticker) basis. Useful to prevent re-calculation of keys per element.

examples

Examples

iex> StickerClient.Crypto.derive_keys("15ec8868cec15c35764af51e09951fc15b548d1dfc1267d0f56bcf7e339b7d09")
{:ok,
{<<157, 123, 104, 238, 5, 106, 230, 214, 253, 151, 230, 234, 151, 95, 32, 176,
  221, 225, 219, 243, 120, 210, 71, 116, 175, 39, 55, 12, 43, 78, 77, 247>>,
<<124, 62, 227, 68, 78, 143, 206, 10, 171, 80, 50, 133, 219, 154, 242, 93, 6,
  140, 58, 98, 2, 68, 110, 40, 98, 252, 58, 176, 55, 15, 149, 227>>}}

iex(1)> StickerClient.Crypto.derive_keys("15e4af51e09951fc15b548d1dfc1267d0f56bcf7e339b7d")
{:error, %StickerClient.Exception{message: "Invalid key size. Expected 64 bytes."}}