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, Nov 23, 10:17 AM
Unknown Object (File)
Sat, Nov 23, 10:12 AM
Unknown Object (File)
Sat, Nov 23, 7:12 AM
Unknown Object (File)
Tue, Nov 12, 11:09 AM
Unknown Object (File)
Sat, Nov 2, 2:54 AM
Unknown Object (File)
Sat, Nov 2, 12:29 AM
Unknown Object (File)
Sat, Nov 2, 12:29 AM
Unknown Object (File)
Sat, Nov 2, 12:29 AM
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
Branch
barthap/aes-web
Lint
No Lint Coverage
Unit
No Test Coverage

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

I think we can do an equality check here?

51

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

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.