Page MenuHomePhabricator

[web] Implement AES encryption functions
ClosedPublic

Authored by bartek on Mar 9 2023, 11:05 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Jun 15, 7:45 PM
Unknown Object (File)
Sat, Jun 15, 6:44 PM
Unknown Object (File)
Thu, Jun 13, 6:46 PM
Unknown Object (File)
Thu, Jun 13, 6:41 PM
Unknown Object (File)
Sat, Jun 8, 2:39 AM
Unknown Object (File)
Sun, May 26, 4:47 PM
Unknown Object (File)
May 19 2024, 4:16 AM
Unknown Object (File)
May 18 2024, 11:03 PM
Subscribers

Details

Summary
Test Plan

Unit tests will be added in next diff.

In root component (or any other) I did:

import * as AES from './utils/aes-crypto-module.js';

const f = async () => {
  const key = await AES.generateKey();
  console.log('Key', key);
  const plaintextBytes = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
  const ciphertext = await AES.encrypt(key, plaintextBytes);
  console.log('Ciphertext', ciphertext);
  const decrypted = await AES.decrypt(key, ciphertext);
  console.log('Decrypted', decrypted); // should be equal to plaintextBytes
};

React.useEffect(() => {
  f();
}, []);

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

bartek held this revision as a draft.
bartek published this revision for review.Mar 9 2023, 11:26 AM

Unit tests will be added in next diff.

Sweet, thanks for handling this

web/utils/aes-crypto.js
50 ↗(On Diff #23587)

I think we can do an equality check here?

51 ↗(On Diff #23587)

We mention "size" in the previous error message:

throw new Error('Invalid AES key size');

Should we do the same here for symmetry?

This revision is now accepted and ready to land.Mar 10 2023, 3:29 PM
  • Rebase on new types
  • Address review feedback
    • Used consistent naming for ciphertext, sealed data etc.
bartek added inline comments.
web/utils/aes-crypto.js
50 ↗(On Diff #23587)

Nope, this can be equal (in case data is 0 length) or longer (with data between them).

Revert accidental changes

This revision is now accepted and ready to land.Mar 13 2023, 5:21 AM
This revision was automatically updated to reflect the committed changes.