Encrypting All Files On Windows System with Go

KanakSasak
2 min readJul 13, 2023

Section 1: Encrypting Files Our Go code starts by defining the root directory where the encryption process will begin. By modifying the root variable, you can specify the desired starting directory. The code scans through all files, targeting popular office file formats like .docx, .xlsx, and .pptx. However, you can customize this list by adding or removing file extensions.

Section 2: Parallel Execution with Goroutines To optimize performance, we employ goroutines to parallelize the encryption process. Goroutines allow us to encrypt multiple files concurrently, significantly reducing processing time. By utilizing the sync.WaitGroup construct, the code ensures that all goroutines complete before proceeding.

Section 3: Generating a Personalized Wallpaper After encrypting the files, our code generates a custom wallpaper image. It creates a black background and adds the text “silahkan periksa file anda” (meaning “please check your files” in Indonesian) using the Go image and image/draw packages. You can modify the addLabel function to add your preferred text or customize the design to match your style.

Section 4: Setting the Wallpaper With the wallpaper image ready, the code saves it to a temporary location, typically the system’s temporary folder. It uses the os.TempDir() function to retrieve the temporary folder path dynamically. From there, the code sets the generated image as the desktop wallpaper using PowerShell commands.

Section 5: Logging Encrypted Files To maintain a record of the encrypted files, the code creates a log file named encryption.log. This log file stores details such as the original filename, encrypted filename, and directory path. Reviewing this log file enables you to cross-reference and verify encrypted files at a later stage.

Conclusion: With this Go code, we’ve combined file encryption, custom wallpaper generation, and desktop background customization into a single program. By harnessing the power of goroutines, encryption becomes faster and more efficient. Additionally, the log file provides an audit trail for encrypted files. Feel free to explore and customize this code to suit your specific needs.

Remember, file encryption is a critical security measure, so exercise caution and ensure you have appropriate permissions before running the code. Stay secure and enjoy your personalized, encrypted desktop experience!

--

--