Skip to content

@fabwcie/free-drawing / utils/encryption

utils/encryption ​

Classes ​

RoomCipher ​

Defined in: packages/free-drawing/src/utils/encryption.ts:56

Encryption of the messages of a room with its key: AES-GCM, a random initialization vector per message, so a message changed or encrypted with another key is not decrypted

Constructors ​

Constructor ​

private new RoomCipher(key, keyCheck, cryptoKey): RoomCipher

Defined in: packages/free-drawing/src/utils/encryption.ts:73

Cipher of a key already imported, see create

Parameters
key ​

string

Key of the room in base64url

keyCheck ​

string

Proof of the key for the server

cryptoKey ​

CryptoKey

Key of Web Crypto

Returns

RoomCipher

Properties ​

key ​

readonly key: string

Defined in: packages/free-drawing/src/utils/encryption.ts:58

Key of the room in base64url, put in its links

keyCheck ​

readonly keyCheck: string

Defined in: packages/free-drawing/src/utils/encryption.ts:63

Proof of the key given to the server when joining (SHA-256 of the key): users with another key, or none, are refused, the key can't be found from it

Methods ​

decrypt() ​

decrypt(data): Promise<string>

Defined in: packages/free-drawing/src/utils/encryption.ts:120

Text decrypted with the key of the room

Parameters
data ​

unknown

Data of encrypt (not trusted)

Returns

Promise<string>

Decrypted text

Throws

data not encrypted with this key, changed, or not encrypted data

decryptJson() ​

decryptJson(data): Promise<unknown>

Defined in: packages/free-drawing/src/utils/encryption.ts:151

Value of encrypted JSON

Parameters
data ​

unknown

Data of encryptJson (not trusted)

Returns

Promise<unknown>

Decrypted value, to check

Throws

data not encrypted with this key, changed, or not JSON

encrypt() ​

encrypt(text): Promise<string>

Defined in: packages/free-drawing/src/utils/encryption.ts:100

Text encrypted with the key of the room

Parameters
text ​

string

Text to encrypt

Returns

Promise<string>

Initialization vector and encrypted text, in base64url

encryptJson() ​

encryptJson(value): Promise<string>

Defined in: packages/free-drawing/src/utils/encryption.ts:141

Value encrypted as JSON

Parameters
value ​

unknown

Value to encrypt (pointer position, view...)

Returns

Promise<string>

Encrypted JSON, see encrypt

fileId() ​

fileId(id): Promise<string>

Defined in: packages/free-drawing/src/utils/encryption.ts:161

Id of an image file in the messages of the room: the same for the same file, so the server keeps it once, and the id of the file (hash of the image) can't be found from it without the key

Parameters
id ​

string

Id of the file

Returns

Promise<string>

SHA-256 of the key and the id, in base64url (43 characters)

create() ​

static create(key): Promise<RoomCipher>

Defined in: packages/free-drawing/src/utils/encryption.ts:85

Cipher of a room

Parameters
key ​

string

Key of the room (22 characters of base64url), from its link

Returns

Promise<RoomCipher>

Cipher ready to encrypt and decrypt

Throws

error.roomKey for a key cut or changed, error.insecurePage on a page without Web Crypto

Variables ​

roomKeyPattern ​

const roomKeyPattern: RegExp

Defined in: packages/free-drawing/src/utils/encryption.ts:13

Key of a room in links: 128 bits in base64url

Functions ​

createRoomKey() ​

createRoomKey(): Promise<string>

Defined in: packages/free-drawing/src/utils/encryption.ts:45

New key of an encrypted room

Returns

Promise<string>

Key of 128 bits in base64url (22 characters), put in the links of the room

Throws

error.insecurePage on a page without Web Crypto


createSecret() ​

createSecret(): string

Defined in: packages/free-drawing/src/utils/encryption.ts:36

Secret that can't be guessed (id of a room, secret of its owner, secret of the browser of a user): random bytes of crypto.getRandomValues, also on pages without Web Crypto (not https), unlike Math.random whose outputs can be found again from the ids of shapes

Returns

string

128 random bits in base64url (22 characters)


decryptChange() ​

decryptChange(cipher, message): Promise<DecryptedChange>

Defined in: packages/free-drawing/src/utils/encryption.ts:228

Change of an encrypted room decrypted: shapes, files and background encrypted with another key, or changed, are dropped (other parts are checked when applied, as in rooms in clear)

Parameters

cipher

RoomCipher

Cipher of the room

message

unknown

Change received from the server (not trusted)

Returns

Promise<DecryptedChange>

Change as in a room in clear, with the number of parts not decrypted


encryptChange() ​

encryptChange(cipher, change): Promise<EncryptedChange>

Defined in: packages/free-drawing/src/utils/encryption.ts:186

Change of the drawing encrypted for an encrypted room: ids of shapes, removed shapes and stacking order in clear (the server keeps the drawing shape by shape), shapes, image files and background encrypted

Parameters

cipher

RoomCipher

Cipher of the room

change

DrawingChange

Change to send

Returns

Promise<EncryptedChange>

Change to send to the server