'How to store encrypted SecretAccessKey in registry for Redshift ODBC driver?

Ideally you create a ODBC DSN using the "ODBC Data Sources" UI.

I am creating a Redshift Driver DSN(TestDSN) using Authentication Type "IAM Credentials"

Amazon Redshift ODBC Driver DSN Setup screenshot

The settings are saved in Registry "HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\TestDSN"

The SecretAccessKey is stored encrypted (image)

Now I want to create a DSN programmatically, and that can be done by creating Registry keys from my code AWS documentation to Configure driver options

But the only problem is, that for Redshift Driver to use this DSN, it needs the SecretAccessKeyEncrypted.

How do I encrypt my SecretAccessKey to store in Registry so I can create a valid Redshift ODBC DSN?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source