Encrypt

Encrypt content for an address public key using the .encrypt() function.

Returns

This will return the encrypted content.

Usage

import { encryption } from 'aleph-js'

await encryption.encrypt(public_key, content)
  
// Or with an additional parameters
await encryption.encrypt(public_key, content, {as_hex: true, as_string: true})

Required parameters

ParameterDescription

public_key** ** - string

Public key used for encrypting the content

content** **

Content to encrypt

Optional parameters

In addition to the required parameters above, an object of optional parameters can be passed following the content like so:

encryption.encrypt(public_key, content,{as_hex: false})

  • as_hex - boolean

    Default: true

    If true, the function will return the encrypted result as a hexadecimal string representation.

  • as_string - boolean

    Default: true

    Should be set to true if the content to encrypt is a string.

  • curve - string: secp256k1 or secp256r1 or ed25519

    Default "secp256k1"

    The curve of encryption, as it can't be deducted from the public key. `` Value can be either secp256k1 or secp256r1 or ed25519

Using the as_hex and as_string options are useful if you want to serialize yourself, or avoid serialization, and if you are working with files (or binary blobs).

Typically, if you want to store an encrypted file, you will handle Buffer objects, and won't serialize in any way (both options will be set to false).

Example

import { encryption } from 'aleph-js'

await aleph.encryption.encrypt(account.public_key, "content to encrypt")
RESPONSE
'04465d5bbda5a12 ... df3ea58ef66041b89e2ac7fa'

Last updated