forked from aws-amplify/amplify-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'aws-amplify:dev' into dev
- Loading branch information
Showing
4 changed files
with
127 additions
and
92 deletions.
There are no files selected for viewing
55 changes: 28 additions & 27 deletions
55
packages/amplify-cli/src/__tests__/utils/encrypt-buffer.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,35 @@ | ||
import { encryptBuffer, encryptKey } from '../../commands/helpers/encryption-helpers' | ||
import { encryptBuffer, encryptKey } from '../../commands/helpers/encryption-helpers'; | ||
import { v4 } from 'uuid'; | ||
import crypto from 'crypto' | ||
describe("encryption helper", () => { | ||
it("tests encryption helper", async() =>{ | ||
const originalKey = v4(); | ||
const plainText = crypto.randomBytes(10); | ||
const encryptedText = await encryptBuffer(plainText, originalKey); | ||
const bData = Buffer.from(encryptedText, 'base64'); | ||
import crypto from 'crypto'; | ||
describe('encryption helper', () => { | ||
it('tests encryption helper', async () => { | ||
const originalKey = v4(); | ||
const plainText = crypto.randomBytes(10); | ||
const encryptedText = await encryptBuffer(plainText, originalKey); | ||
const bData = Buffer.from(encryptedText, 'base64'); | ||
|
||
// convert data to buffers | ||
const salt = bData.slice(0, 64); | ||
const iv = bData.slice(64, 80); | ||
const tag = bData.slice(80, 96); | ||
const text = bData.slice(96); | ||
// convert data to buffers | ||
const salt = bData.slice(0, 64); | ||
const iv = bData.slice(64, 80); | ||
const tag = bData.slice(80, 96); | ||
const text = bData.slice(96); | ||
|
||
const masterkey = Buffer.from(originalKey, 'utf-8'); | ||
const masterkey = Buffer.from(originalKey, 'utf-8'); | ||
|
||
// derive key using; 32 byte key length | ||
const key = crypto.pbkdf2Sync(masterkey, salt , 2145, 32, 'sha512'); | ||
// derive key using; 32 byte key length | ||
const key = crypto.pbkdf2Sync(masterkey, salt, 2145, 32, 'sha512'); | ||
|
||
// AES 256 GCM Mode | ||
const decipher = crypto.createDecipheriv('aes-256-gcm', key, iv); | ||
decipher.setAuthTag(tag); | ||
// AES 256 GCM Mode | ||
const decipher = crypto.createDecipheriv('aes-256-gcm', key, iv); | ||
decipher.setAuthTag(tag); | ||
|
||
// encrypt the given text | ||
const decrypted = decipher.update(text, 'binary', 'utf8') + decipher.final('utf8'); | ||
expect(decrypted).toEqual(plainText.toString('utf8')); | ||
}); | ||
// encrypt the given text | ||
const decrypted = decipher.update(text, 'binary', 'utf8') + decipher.final('utf8'); | ||
expect(decrypted).toEqual(plainText.toString('utf8')); | ||
}); | ||
|
||
it("test encryption key", async () => { | ||
expect(await encryptKey(v4())).toBeTruthy(); | ||
}) | ||
}) | ||
it('test encryption key', async () => { | ||
jest.setTimeout(10000); | ||
expect(await encryptKey(v4())).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.