File tree 2 files changed +4
-6
lines changed
2 files changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -34,21 +34,20 @@ async function decrypt(
34
34
35
35
// Reads the file to be decrypted
36
36
const readFile = promisify ( fs . readFile ) ;
37
- const contentsBuffer = await readFile ( ciphertextFileName ) ;
37
+ const ciphertext = await readFile ( ciphertextFileName ) ;
38
38
const name = client . cryptoKeyPath (
39
39
projectId ,
40
40
locationId ,
41
41
keyRingId ,
42
42
cryptoKeyId
43
43
) ;
44
- const ciphertext = contentsBuffer . toString ( 'base64' ) ;
45
44
46
45
// Decrypts the file using the specified crypto key
47
46
const [ result ] = await client . decrypt ( { name, ciphertext} ) ;
48
47
49
48
// Writes the decrypted file to disk
50
49
const writeFile = promisify ( fs . writeFile ) ;
51
- await writeFile ( plaintextFileName , Buffer . from ( result . plaintext , 'base64' ) ) ;
50
+ await writeFile ( plaintextFileName , result . plaintext ) ;
52
51
console . log (
53
52
`Decrypted ${ ciphertextFileName } , result saved to ${ plaintextFileName } .`
54
53
) ;
Original file line number Diff line number Diff line change @@ -34,8 +34,7 @@ async function encrypt(
34
34
35
35
// Reads the file to be encrypted
36
36
const readFile = promisify ( fs . readFile ) ;
37
- const contentsBuffer = await readFile ( plaintextFileName ) ;
38
- const plaintext = contentsBuffer . toString ( 'base64' ) ;
37
+ const plaintext = await readFile ( plaintextFileName ) ;
39
38
const name = client . cryptoKeyPath (
40
39
projectId ,
41
40
locationId ,
@@ -46,7 +45,7 @@ async function encrypt(
46
45
// Encrypts the file using the specified crypto key
47
46
const [ result ] = await client . encrypt ( { name, plaintext} ) ;
48
47
const writeFile = promisify ( fs . writeFile ) ;
49
- await writeFile ( ciphertextFileName , Buffer . from ( result . ciphertext , 'base64' ) ) ;
48
+ await writeFile ( ciphertextFileName , result . ciphertext ) ;
50
49
console . log ( `Encrypted ${ plaintextFileName } using ${ result . name } .` ) ;
51
50
console . log ( `Result saved to ${ ciphertextFileName } .` ) ;
52
51
}
You can’t perform that action at this time.
0 commit comments