
public final class SecuredProperties extends Object
Example:
The Property file "myConfiguration.properties":
mySecretPassword = testThe Java code:
// prepare custom config
final SecuredPropertiesConfig config = new SecuredPropertiesConfig().withSecretFile(new File("G:/mysecret.key")).initDefault();
// auto-encrypt values in the property-file:
SecuredProperties.encryptNonEncryptedValues(config,
new File("myConfiguration.properties"), // The Property File
"mySecretPassword"); // the property-key from "myConfiguration.properties"
// read encrypted values from the property-file
String secretValue = SecuredProperties.getSecretValue(config,
new File("myConfiguration.properties"), // The Property File
"mySecretPassword"); // the property-key from "myConfiguration.properties"
will return "test" as secretValue and automatically encrypt the value in the property file. After the first run the Property file will looks similar to the
following:
mySecretPassword = {wVtvW8lQrwCf8MA9sadwww==}
This encrypted password can now be read only in combination with the secret file "G:/mysecret.key"| Modifier and Type | Method and Description |
|---|---|
static String |
decrypt(SecuredPropertiesConfig config,
String encryptedPassword)
Encrypt the given password (will create the secret key if not already exist).
|
static String |
encrypt(SecuredPropertiesConfig config,
String plainTextValue)
Encrypt the given value (will create the secret key if not already exist).
|
static void |
encryptNonEncryptedValues(SecuredPropertiesConfig config,
File[] propertyFiles,
String... keys) |
static void |
encryptNonEncryptedValues(SecuredPropertiesConfig config,
File propertyFile,
String... keys) |
static String |
getSecretValue(SecuredPropertiesConfig config,
File[] propertyFiles,
String key) |
static String |
getSecretValue(SecuredPropertiesConfig config,
File propertyFile,
String key) |
static Map<String,String> |
getSecretValues(SecuredPropertiesConfig config,
File[] propertyFiles,
String... keys) |
static Map<String,String> |
getSecretValues(SecuredPropertiesConfig config,
File propertyFile,
String... keys) |
static boolean |
isEncryptedValue(String maybeEncryptedValue)
Checks if the given String looks like an encrypted value.
|
public static String getSecretValue(SecuredPropertiesConfig config, File propertyFile, String key)
config - the SecuredPropertiesConfig to control custom behavior.propertyFile - The Properties file to with the encrypted valuekey - The Property-Key of the encrypted value.SecuredPropertiespublic static String getSecretValue(SecuredPropertiesConfig config, File[] propertyFiles, String key)
config - the SecuredPropertiesConfig to control custom behavior.propertyFiles - A list of Property file to with the encrypted valuekey - The Property-Key of the encrypted value.SecuredPropertiespublic static Map<String,String> getSecretValues(SecuredPropertiesConfig config, File propertyFile, String... keys)
config - the SecuredPropertiesConfig to control custom behavior.propertyFile - The Properties file to with the encrypted valuekeys - The Property-Keys of the encrypted value.SecuredPropertiespublic static Map<String,String> getSecretValues(SecuredPropertiesConfig config, File[] propertyFiles, String... keys)
config - the SecuredPropertiesConfig to control custom behavior.propertyFiles - A list of Property file to with the encrypted valuekeys - The Property-Keys of the encrypted value.SecuredPropertiespublic static void encryptNonEncryptedValues(SecuredPropertiesConfig config, File propertyFile, String... keys)
config - the SecuredPropertiesConfig to control custom behavior.propertyFile - The Properties file to with the encrypted valuekeys - The Property-Keys of the encrypted value.SecuredPropertiespublic static void encryptNonEncryptedValues(SecuredPropertiesConfig config, File[] propertyFiles, String... keys)
config - the SecuredPropertiesConfig to control custom behavior.propertyFiles - A list of Property file to with the encrypted valuekeys - The Property-Keys of the encrypted value.SecuredPropertiespublic static boolean isEncryptedValue(String maybeEncryptedValue)
public static String encrypt(SecuredPropertiesConfig config, String plainTextValue)
config - the SecuredPropertiesConfig to control custom behavior.plainTextValue - The value to encryptpublic static String decrypt(SecuredPropertiesConfig config, String encryptedPassword)
config - the SecuredPropertiesConfig to control custom behavior.encryptedPassword - The password to encryptCopyright © 2016–2019 Brabenetz Harald, Austria. All rights reserved.