* Create a complete R3 encryption setup for testing.
( userPassword: string, ownerPassword: string, permissions: Permissions = DEFAULT_PERMISSIONS, )
| 21 | * Create a complete R3 encryption setup for testing. |
| 22 | */ |
| 23 | function createR3Setup( |
| 24 | userPassword: string, |
| 25 | ownerPassword: string, |
| 26 | permissions: Permissions = DEFAULT_PERMISSIONS, |
| 27 | ) { |
| 28 | const userPwd = new TextEncoder().encode(userPassword); |
| 29 | const ownerPwd = new TextEncoder().encode(ownerPassword); |
| 30 | const fileId = new Uint8Array(32); |
| 31 | |
| 32 | for (let i = 0; i < 32; i++) { |
| 33 | fileId[i] = i; |
| 34 | } |
| 35 | |
| 36 | const keyLength = 16; // 128-bit |
| 37 | const revision = 3; |
| 38 | const permissionsRaw = encodePermissions(permissions); |
| 39 | |
| 40 | // Generate encryption dictionary values |
| 41 | const ownerHash = computeOwnerHash(ownerPwd, userPwd, keyLength, revision); |
| 42 | const encryptionKey = computeEncryptionKeyR2R4( |
| 43 | userPwd, |
| 44 | ownerHash, |
| 45 | permissionsRaw, |
| 46 | fileId, |
| 47 | keyLength, |
| 48 | revision, |
| 49 | ); |
| 50 | const userHash = computeUserHash(encryptionKey, fileId, revision); |
| 51 | |
| 52 | const encryptDict: EncryptionDict = { |
| 53 | filter: "Standard", |
| 54 | version: 2, |
| 55 | revision: 3, |
| 56 | keyLengthBits: 128, |
| 57 | ownerHash, |
| 58 | userHash, |
| 59 | permissions, |
| 60 | permissionsRaw, |
| 61 | encryptMetadata: true, |
| 62 | algorithm: "RC4", |
| 63 | }; |
| 64 | |
| 65 | return { encryptDict, fileId, encryptionKey, userPwd, ownerPwd }; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Create a complete R4 (AES-128) encryption setup for testing. |
no test coverage detected