/** * Copyright (c) "Neo4j" * Neo4j Sweden AB [https://neo4j.com] * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { BoltProvider } from '../internal/bolt-provider'; import { EncapsulatedKeyManager } from './encapsulated-key-manager'; import { EncryptionProfile } from './encryption-profile'; import UnsupportedType from '../unsupported-type'; /** * Provides Neo4j Property Encryption functions. * * @since 6.3.0 * @experimental Part of the Client-Side Encrytion preview feature */ export default class EncryptionService { private readonly _boltProvider; private readonly _profiles; private readonly _cryptoProvider; /** * @private */ constructor(boltProvider: BoltProvider, profiles: EncryptionProfile[]); /** * Encrypts data with AES-GCM 256 into a byte array ready to be saved an a property in a Neo4j database. * The byte array includes metadata required to allow another Neo4j Driver configured with the same {@link EncapsulatedKeyRecordRepository} to decrypt the data. * * @param {Object} encryptRequest - The value to encrypt and associated metadata for the encryption * @param {any} encryptRequest.value - The value to encrypt, must be a value able to be saved as a Neo4j Property. * @param {string | Object | undefined} encryptRequest.keyOptions - Used to determine the key to be used, a plain string is assumed to be the id, if omitted the encryption profile's default key reference will be used * @param {string} encryptRequest.encryptionProfile - Name of the {@link EncryptionProfile} to use, must be provided unless the driver is configured with only 1 profile. * @param {any | undefined} encryptRequest.aad - Additional Authenticated Data for the encryption. * * @returns {Promise} A Int8Array that can be stored as a ByteArray in a Neo4j database. */ encrypt(encryptRequest: { value: any; keyOptions: string | { alias?: string; id?: string; }; encryptionProfile?: string; aad?: any; }): Promise; /** * Decrypts data encrypted with this or another Neo4j Driver's {@link EncryptionService#encrypt} function. * * @param {Object} decryptRequest - Object containing encrypted ciphertext and required metadata. * @param {Int8Array} decryptRequest.ciphertext - The encrypted ciphertext * @param {any | undefined} decryptRequest.aad - The Additional Authenticated Data to verify when decrypting * @param {boolean | undefined} decryptRequest.usePersistedAad - Wether to use the persisted aad data stored with the ciphertext, mutually exclusive with decryptRequest.aad * * @returns {Promise} The decrypted property or an {@link UnsupportedType} if decoding the decrypted bytes failed. */ decrypt(decryptRequest: { ciphertext: Int8Array; usePersistedAad?: boolean; aad?: any; }): Promise; /** * Returns the key manager for the specified profile * * @param {string | undefined} profileName name of the profile to get the key manager of, can be omitted if driver is configured with only one encryption profile * @returns {EncapsulatedKeyManager} The key manager of the specified profile. */ keyManager(profileName: string | undefined): EncapsulatedKeyManager; private _identifyType; private _getProfile; private _getKeyRecord; private _decapsulateKey; }