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.
 
 
 
 
 
 

15 lines
676 B

import { EncryptionService } from "./EncryptionService";
import * as sjcl from "sjcl";
import { MessageCipherDTO } from "../dto/MessageCipherDTO";
export class SJCLEncryptionService implements EncryptionService {
private readonly params = { mode: "gcm", ts: 128, adata: "", iter: 10000 }
public encrypt(passphrase: string, plainText: string): MessageCipherDTO {
// @ts-ignore
return JSON.parse(sjcl.encrypt(passphrase, plainText, this.params) as string) as MessageCipherDTO;
}
public decrypt(passphrase: string, cipher: MessageCipherDTO): string {
return sjcl.decrypt(passphrase, JSON.stringify(cipher), undefined, undefined);
}
}