A self hosted chat application with end-to-end encrypted messaging.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

14 lines
676 B

  1. import { EncryptionService } from "./EncryptionService";
  2. import * as sjcl from "sjcl";
  3. import { MessageCipherDTO } from "../dto/MessageCipherDTO";
  4. export class SJCLEncryptionService implements EncryptionService {
  5. private readonly params = { mode: "gcm", ts: 128, adata: "", iter: 10000 }
  6. public encrypt(passphrase: string, plainText: string): MessageCipherDTO {
  7. // @ts-ignore
  8. return JSON.parse(sjcl.encrypt(passphrase, plainText, this.params) as string) as MessageCipherDTO;
  9. }
  10. public decrypt(passphrase: string, cipher: MessageCipherDTO): string {
  11. return sjcl.decrypt(passphrase, JSON.stringify(cipher), undefined, undefined);
  12. }
  13. }