|
1 | 1 | import { beforeAll, describe, expect, it } from 'vitest'
|
2 | 2 | import { deriveKeyPbkdf2 } from '../crypto'
|
3 |
| -import { toBase64 } from '../data/bin' |
| 3 | +import { fromBase64, toBase64 } from '../data/bin' |
4 | 4 | import { hxDecrypt, hxEncrypt } from './aes-sealed'
|
5 | 5 |
|
6 | 6 | describe('aes Encryption and Decryption', () => {
|
@@ -46,20 +46,34 @@ describe('aes Encryption and Decryption', () => {
|
46 | 46 | })
|
47 | 47 |
|
48 | 48 | it('should decrypt a sample that was generated by Swift code', async () => {
|
49 |
| - const key = await deriveKeyPbkdf2(new Uint8Array([1, 2, 3]), { |
50 |
| - salt: new Uint8Array([1, 2, 3]), |
| 49 | + const key = await deriveKeyPbkdf2(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]), { |
| 50 | + salt: new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]), |
51 | 51 | iterations: 100000,
|
52 | 52 | })
|
53 | 53 | const dataFromKey = await crypto.subtle.exportKey('raw', key)
|
54 |
| - expect(toBase64(dataFromKey)).toMatchInlineSnapshot(`"+EZYmOnuVat0rvokPjZxkwdGacOiFvR2oaukTeVa84M="`) |
| 54 | + expect(toBase64(dataFromKey)).toMatchInlineSnapshot(`"UDl7buu/Zn/UxCIEp55MOTOKcDHvb959P+eyozok7BA="`) |
55 | 55 |
|
56 | 56 | const sample = new Uint8Array([9, 8, 7, 6, 5, 4, 3, 2, 1, 0])
|
57 |
| - const encryptedData = await hxEncrypt(sample, key) |
58 |
| - expect(toBase64(encryptedData)).toMatchInlineSnapshot( |
59 |
| - `"WbwhO/CaS3W4VxiIIG3Zs4WdEa08CzEFgaQLs0TrRDejZ/8G0yu0S1JIV+3bn79O7SeyCfI0"`, |
60 |
| - ) |
61 |
| - // const encryptedData = fromBase64('br6sc+pnZaIXcV1fTygAs/UJlDZIIBY50i56MMGNampZTcSakt0=') |
62 |
| - // const decryptedData = await hxDecrypt(encryptedData, key) |
63 |
| - // expect(decryptedData).toMatchInlineSnapshot() |
| 57 | + // const encryptedData = await hxEncrypt(sample, key) |
| 58 | + // expect(toBase64(encryptedData)).toMatchInlineSnapshot( |
| 59 | + // `"WbwhO/CaS3W4VxiIIG3Zs4WdEa08CzEFgaQLs0TrRDejZ/8G0yu0S1JIV+3bn79O7SeyCfI0"`, |
| 60 | + // ) |
| 61 | + |
| 62 | + const encryptedData = fromBase64('AQIDBAUGBwgJCgsMqZ0hGHIvSPG5x0d12q42zezDEJVu8Ic3yB4=') |
| 63 | + const decryptedData = await hxDecrypt(encryptedData, key) |
| 64 | + expect(decryptedData).toMatchInlineSnapshot(` |
| 65 | + Uint8Array [ |
| 66 | + 9, |
| 67 | + 8, |
| 68 | + 7, |
| 69 | + 6, |
| 70 | + 5, |
| 71 | + 4, |
| 72 | + 3, |
| 73 | + 2, |
| 74 | + 1, |
| 75 | + 0, |
| 76 | + ] |
| 77 | + `) |
64 | 78 | })
|
65 | 79 | })
|
0 commit comments