Bulk Encrypt Files
Bulk Encrypt and Decrypt Files using the Virtru SDK
Today I will be looking at a fairly simple use case of bulk encrypt and decrypt operations local to a machine using the Virtru SDK.
Tools And Code
Why
I am moving a lot of files from my local computer to the cloud. Some of the files contain sensitive information, so I would like to encrypt them. I plan on moving the files into a specific folder and encrypting those files. Once complete I will migrate all data.
How
Using the existing sample from the Virtru Developer Hub where the sample took all of the files in a directory and encrypted them, I extended it and parameterized it.
Code
Encrypt
Decrypt
Both of these code blocks are similar because they are mostly looping through the files in the folder and performing the action requested. The main difference between them is the renaming of the files. In this example, I assume the files will be created in zip format, which implies a tdf3 file extension for encryption. When decrypting, the files may be either tdf3 or tdf3.html. I created a function to handle the rename logic.
Closing
Creating a quick application that I can use in my day to day work has helped me to easily add the call in an existing cron job. The code is very straight forward, except for the naming parts.