Skip to content

Commit 67108d3

Browse files
bdhessAce Nassri
authored and
Ace Nassri
committed
fix: remove superfluous base64-encoding/decoding (#242)
1 parent 0a242af commit 67108d3

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

kms/decrypt.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,20 @@ async function decrypt(
3434

3535
// Reads the file to be decrypted
3636
const readFile = promisify(fs.readFile);
37-
const contentsBuffer = await readFile(ciphertextFileName);
37+
const ciphertext = await readFile(ciphertextFileName);
3838
const name = client.cryptoKeyPath(
3939
projectId,
4040
locationId,
4141
keyRingId,
4242
cryptoKeyId
4343
);
44-
const ciphertext = contentsBuffer.toString('base64');
4544

4645
// Decrypts the file using the specified crypto key
4746
const [result] = await client.decrypt({name, ciphertext});
4847

4948
// Writes the decrypted file to disk
5049
const writeFile = promisify(fs.writeFile);
51-
await writeFile(plaintextFileName, Buffer.from(result.plaintext, 'base64'));
50+
await writeFile(plaintextFileName, result.plaintext);
5251
console.log(
5352
`Decrypted ${ciphertextFileName}, result saved to ${plaintextFileName}.`
5453
);

kms/encrypt.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ async function encrypt(
3434

3535
// Reads the file to be encrypted
3636
const readFile = promisify(fs.readFile);
37-
const contentsBuffer = await readFile(plaintextFileName);
38-
const plaintext = contentsBuffer.toString('base64');
37+
const plaintext = await readFile(plaintextFileName);
3938
const name = client.cryptoKeyPath(
4039
projectId,
4140
locationId,
@@ -46,7 +45,7 @@ async function encrypt(
4645
// Encrypts the file using the specified crypto key
4746
const [result] = await client.encrypt({name, plaintext});
4847
const writeFile = promisify(fs.writeFile);
49-
await writeFile(ciphertextFileName, Buffer.from(result.ciphertext, 'base64'));
48+
await writeFile(ciphertextFileName, result.ciphertext);
5049
console.log(`Encrypted ${plaintextFileName} using ${result.name}.`);
5150
console.log(`Result saved to ${ciphertextFileName}.`);
5251
}

0 commit comments

Comments
 (0)