Encryption / Decryption

Once you have the user's keys, you can easily encrypt and decrypt messages:

Encrypt

Simply pass the public key of the receiver and the message to obtain the encrypted message.

const encryptedMessage = encrypt(receiverPublicKey: Uint8Array, 
message: string | Uint8Array, toHex?: boolean);

Parameters description

ParameterDescriptionOptional

receiverPublicKey

The public key of the receiver, obtained from Ceramic and the user's address

No

message

Message as Uint8Array or string

No

toHex

Whether to convert the encrypted message to a hexadecimal string or not.

Yes

Decrypt

Likewise, pass the public key of the sender and the message to obtain the decrypted message.

const decryptedMessage = encrypt(senderPublicKey: Uint8Array, 
message: string | Uint8Array);

Parameters description

ParameterDescriptionOptional

senderPublicKey

The public key of the sender, obtained from Ceramic and the user's address

No

message

Encrypted message as Uint8Array or string

No

Last updated