2022-10-27 23:38:54 +02:00
|
|
|
import { Decryptable } from "../interfaces/decryptable.interface";
|
2023-06-06 22:34:53 +02:00
|
|
|
import { Encrypted } from "../interfaces/encrypted";
|
2022-10-27 23:38:54 +02:00
|
|
|
import { InitializerMetadata } from "../interfaces/initializer-metadata.interface";
|
2022-10-14 18:25:50 +02:00
|
|
|
import { EncArrayBuffer } from "../models/domain/enc-array-buffer";
|
|
|
|
import { EncString } from "../models/domain/enc-string";
|
|
|
|
import { SymmetricCryptoKey } from "../models/domain/symmetric-crypto-key";
|
2022-07-26 03:40:32 +02:00
|
|
|
|
2022-10-27 23:38:54 +02:00
|
|
|
export abstract class EncryptService {
|
2023-08-04 04:13:33 +02:00
|
|
|
abstract encrypt(plainValue: string | Uint8Array, key: SymmetricCryptoKey): Promise<EncString>;
|
2024-03-28 12:01:09 +01:00
|
|
|
abstract encryptToBytes(
|
2023-08-04 04:13:33 +02:00
|
|
|
plainValue: Uint8Array,
|
2022-07-26 03:40:32 +02:00
|
|
|
key?: SymmetricCryptoKey,
|
2024-03-28 12:01:09 +01:00
|
|
|
): Promise<EncArrayBuffer>;
|
|
|
|
abstract decryptToUtf8(encString: EncString, key: SymmetricCryptoKey): Promise<string>;
|
|
|
|
abstract decryptToBytes(encThing: Encrypted, key: SymmetricCryptoKey): Promise<Uint8Array>;
|
|
|
|
abstract rsaEncrypt(data: Uint8Array, publicKey: Uint8Array): Promise<EncString>;
|
|
|
|
abstract rsaDecrypt(data: EncString, privateKey: Uint8Array): Promise<Uint8Array>;
|
|
|
|
abstract resolveLegacyKey(key: SymmetricCryptoKey, encThing: Encrypted): SymmetricCryptoKey;
|
|
|
|
abstract decryptItems<T extends InitializerMetadata>(
|
2022-10-27 23:38:54 +02:00
|
|
|
items: Decryptable<T>[],
|
|
|
|
key: SymmetricCryptoKey,
|
2024-03-28 12:01:09 +01:00
|
|
|
): Promise<T[]>;
|
2024-01-24 18:22:58 +01:00
|
|
|
/**
|
|
|
|
* Generates a base64-encoded hash of the given value
|
|
|
|
* @param value The value to hash
|
|
|
|
* @param algorithm The hashing algorithm to use
|
|
|
|
*/
|
2024-03-28 12:01:09 +01:00
|
|
|
abstract hash(
|
|
|
|
value: string | Uint8Array,
|
|
|
|
algorithm: "sha1" | "sha256" | "sha512",
|
|
|
|
): Promise<string>;
|
2022-06-27 19:38:12 +02:00
|
|
|
}
|