| 18 | } |
| 19 | |
| 20 | class AesEncryptionLibrary implements EncryptionLibrary { |
| 21 | deriveKey = async ( |
| 22 | password: string, |
| 23 | salt: string, |
| 24 | opts: KeyDerivationOptions, |
| 25 | ): Promise<string> => { |
| 26 | checkForKDFAlgorithm(opts.algorithm); |
| 27 | |
| 28 | return await Aes.pbkdf2( |
| 29 | password, |
| 30 | salt, |
| 31 | opts.params.iterations, |
| 32 | SHA256_DIGEST_LENGTH, |
| 33 | ); |
| 34 | }; |
| 35 | |
| 36 | generateIV = async (size: number): Promise<string> => |
| 37 | // Naming isn't perfect here, but this is how the library generates random IV (and encodes it the right way) |
| 38 | // See: https://www.npmjs.com/package/react-native-aes-crypto#example |
| 39 | await Aes.randomKey(size); |
| 40 | |
| 41 | encrypt = async (data: string, key: string, iv: unknown): Promise<string> => |
| 42 | await Aes.encrypt(data, key, iv); |
| 43 | |
| 44 | decrypt = async (data: string, key: string, iv: unknown): Promise<string> => |
| 45 | await Aes.decrypt(data, key, iv); |
| 46 | } |
| 47 | |
| 48 | class AesForkedEncryptionLibrary implements EncryptionLibrary { |
| 49 | deriveKey = async ( |
nothing calls this directly
no test coverage detected