38 private cipherMap: Record<string, BaseCipher> = {};
46 const cipherClasses = [
80 for (
const CipherClass of cipherClasses) {
94 private normalize(name:
string):
string {
95 return name.toLowerCase().replace(/\s+/g,
'');
108 encode(plaintext:
string, key?: any, cipherName?:
string):
string {
110 throw new Error(
"Cipher name required");
112 const cipher = this.cipherMap[this.normalize(cipherName)];
114 throw new Error(`
Cipher "${cipherName}" not found`);
116 return cipher.encode(plaintext, key);
129 decode(ciphertext:
string, key?: any, cipherName?:
string):
string {
131 throw new Error(
"Cipher name required");
133 const cipher = this.cipherMap[this.normalize(cipherName)];
135 throw new Error(`
Cipher "${cipherName}" not found`);
137 return cipher.decode(ciphertext, key);
147 return Object.keys(this.cipherMap);