/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { Bytes } from "#util/Bytes.js";
const NONCE_LENGTH = 13;
class AesCipher {
  #crypto;
  #key;
  constructor(crypto, key) {
    this.#crypto = crypto;
    this.#key = key;
  }
  encrypt(data) {
    const nonce = this.#crypto.randomBytes(NONCE_LENGTH);
    const ciphertext = this.#crypto.encrypt(this.#key, data, nonce);
    const result = new Uint8Array(NONCE_LENGTH + ciphertext.byteLength);
    result.set(Bytes.of(nonce), 0);
    result.set(Bytes.of(ciphertext), NONCE_LENGTH);
    return result;
  }
  decrypt(data) {
    const bytes = Bytes.of(data);
    const nonce = bytes.subarray(0, NONCE_LENGTH);
    const ciphertext = bytes.subarray(NONCE_LENGTH);
    return Bytes.of(this.#crypto.decrypt(this.#key, ciphertext, nonce));
  }
}
export {
  AesCipher
};
//# sourceMappingURL=Cipher.js.map
