WIP: create encrypt with IV methods in SymmetricCipherFacade

This commit is contained in:
vaf 2025-12-01 17:38:06 +01:00
parent 96c1e1d940
commit 73d7ddf371
No known key found for this signature in database
GPG key ID: 2AE9A7F02CCE35DC
3 changed files with 26 additions and 3 deletions

View file

@ -28,7 +28,7 @@ export class AesCbcFacade {
encrypt(
key: AesKey,
plainText: Uint8Array,
hasRandomIvToPrepend: boolean,
mustPrependIv: boolean,
iv: Uint8Array,
padding: boolean,
cipherVersion: SymmetricCipherVersion,
@ -40,7 +40,7 @@ export class AesCbcFacade {
)
let unauthenticatedCiphertext
if (hasRandomIvToPrepend) {
if (mustPrependIv) {
//version byte is not included into authentication tag for legacy reasons
unauthenticatedCiphertext = concat(iv, cipherText)
} else {

View file

@ -42,6 +42,29 @@ export class SymmetricCipherFacade {
return this.encrypt(key, bytes, true, SymmetricCipherVersion.UnusedReservedUnauthenticated, true)
}
/**
* Encrypts a byte array with AES in CBC mode with a custom IV.
*
* Forces encryption without authentication. The custom IV is prepended to the returned CBC ciphertext.
*
* @deprecated
*/
encryptValueDeprecatedUnauthenticated(key: AesKey, bytes: Uint8Array, iv: Uint8Array): Uint8Array {
// TODO
return this.aesCbcFacade.encrypt(key, bytes, true, iv, true, SymmetricCipherVersion.AesCbcThenHmac)
}
/**
* Encrypts a byte array with AES in CBC mode with a custom IV.
*
* Forces encryption without authentication. The custom IV is prepended to the returned CBC ciphertext.
*
* @deprecated
*/
encryptDatabaseKeyDeprecatedUnauthenticated(key: AesKey, bytes: Uint8Array, iv: Uint8Array): Uint8Array {
return this.aesCbcFacade.encrypt(key, bytes, true, iv, true, SymmetricCipherVersion.UnusedReservedUnauthenticated, true)
}
/**
* Decrypts byte array with AES in CBC mode.
*

View file

@ -26,7 +26,7 @@ export class SymmetricKeyDeriver {
switch (symmetricCipherVersion) {
case SymmetricCipherVersion.UnusedReservedUnauthenticated:
//we allow unauthenticated encryption of search index
if (keyLength !== AesKeyLength.Aes128 && skipAuthentication === false) {
if (keyLength !== AesKeyLength.Aes128 && !skipAuthentication) {
throw new CryptoError("key length " + keyLength + " is incompatible with cipherVersion " + symmetricCipherVersion)
}
return { encryptionKey: key, authenticationKey: null }