Skip to content

Commit

Permalink
add non-random aes-gcm encryption test (#811)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikolsson authored Aug 18, 2024
1 parent 584b9ba commit 8f5c8be
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/sdk/src/crypto_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import crypto from 'crypto'
import { deriveKeyAndIV } from './crypto_utils'
import { deriveKeyAndIV, encryptAESGCM } from './crypto_utils'

describe('crypto_utils', () => {
test('derivedKeyAndIV', async () => {
Expand All @@ -16,6 +16,24 @@ describe('crypto_utils', () => {
expect(key1.toString()).toEqual(key2.toString())
expect(iv1.toString()).toEqual(iv2.toString())
})

test('aesGcmEncryption', async () => {
const keyPhrase = '0xaabbccddeeff00112233445566778899'
const { key, iv } = await deriveKeyAndIV(keyPhrase)

const plaintext = new Uint8Array([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
])

const { ciphertext } = await encryptAESGCM(plaintext, key, iv)
expect(ciphertext).toEqual(
new Uint8Array([
241, 174, 242, 10, 73, 18, 35, 179, 216, 45, 231, 145, 130, 224, 207, 196, 199, 179,
167, 153, 119, 212, 159, 228, 232, 30, 108, 251, 1, 165, 140, 231, 68, 57, 22, 5,
121,
]),
)
})
})

function generateRandomSpaceId(): string {
Expand Down

0 comments on commit 8f5c8be

Please sign in to comment.