* Create a complete R4 (AES-128) encryption setup for testing.
( userPassword: string, ownerPassword: string, permissions: Permissions = DEFAULT_PERMISSIONS, )
| 69 | * Create a complete R4 (AES-128) encryption setup for testing. |
| 70 | */ |
| 71 | function createR4Setup( |
| 72 | userPassword: string, |
| 73 | ownerPassword: string, |
| 74 | permissions: Permissions = DEFAULT_PERMISSIONS, |
| 75 | ) { |
| 76 | const userPwd = new TextEncoder().encode(userPassword); |
| 77 | const ownerPwd = new TextEncoder().encode(ownerPassword); |
| 78 | const fileId = new Uint8Array(32); |
| 79 | |
| 80 | for (let i = 0; i < 32; i++) { |
| 81 | fileId[i] = i; |
| 82 | } |
| 83 | |
| 84 | const keyLength = 16; // 128-bit |
| 85 | const revision = 4; |
| 86 | const permissionsRaw = encodePermissions(permissions); |
| 87 | |
| 88 | // Generate encryption dictionary values |
| 89 | const ownerHash = computeOwnerHash(ownerPwd, userPwd, keyLength, revision); |
| 90 | const encryptionKey = computeEncryptionKeyR2R4( |
| 91 | userPwd, |
| 92 | ownerHash, |
| 93 | permissionsRaw, |
| 94 | fileId, |
| 95 | keyLength, |
| 96 | revision, |
| 97 | ); |
| 98 | const userHash = computeUserHash(encryptionKey, fileId, revision); |
| 99 | |
| 100 | const encryptDict: EncryptionDict = { |
| 101 | filter: "Standard", |
| 102 | version: 4, |
| 103 | revision: 4, |
| 104 | keyLengthBits: 128, |
| 105 | ownerHash, |
| 106 | userHash, |
| 107 | permissions, |
| 108 | permissionsRaw, |
| 109 | encryptMetadata: true, |
| 110 | algorithm: "AES-128", |
| 111 | }; |
| 112 | |
| 113 | return { encryptDict, fileId, encryptionKey, userPwd, ownerPwd }; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Create a complete R6 (AES-256) encryption setup for testing. |
no test coverage detected