encryptionkeysharedcleartext

How to write library to decrypt something without write secret key in clear text?


I'm using an utils library to encrypt/decrypt data simply by calling methods with folowing signature:

String encrypt(String clearText, String secretKey)
String decrypt(String encryptedText, String secretKey)

Both encrypt/decrypt methods use the same logic and encryption. It means that same input to the methods generates always the same output.

The purpose now is to write an helper method to decrypt some connection strings previously stored in a file using the encrypt method. This helper method should call the decrypt function calling it with the secretKey in clear text:

String connectionStringEncrypted = Utils.getProperty("connectionString", "C:\\Path\\To\\application.properties");
String connectionString = Utils.decryptConnectionString(connectionStringEncrypted);

The question is: how can I avoid to write the secret key in clear text in the helper method Utils.decryptConnectionString?


Solution

  • There are too many simple and complex methods to address this issue I can tell some, Starting from Simple Methods

    Advanced Methods: