1 /*-
2 * #%L
3 * Secured Properties
4 * ===============================================================
5 * Copyright (C) 2016 Brabenetz Harald, Austria
6 * ===============================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * #L%
19 */
20 package net.brabenetz.lib.securedproperties.snippets;
21
22 // START SNIPPET: configExample
23 import net.brabenetz.lib.securedproperties.SecuredProperties;
24 import net.brabenetz.lib.securedproperties.SecuredPropertiesConfig;
25
26 import java.io.File;
27
28 public class SpringBootSecuredPropertiesHelper {
29 // Here you should look if you maybe need a custom config:
30 private static final SecuredPropertiesConfig config = new SecuredPropertiesConfig().initDefault();
31
32 // the same property files which are supported by spring-boot:
33 private static File[] propertyFiles = new File[] {new File("./config/application.properties"), new File("./application.properties")};
34
35 public static void encryptProperties(String... keys) {
36 SecuredProperties.encryptNonEncryptedValues(config, propertyFiles, keys);
37 }
38
39 public static String decrypt(String value) {
40 if (SecuredProperties.isEncryptedValue(value)) {
41 return SecuredProperties.decrypt(config, value);
42 }
43 return value;
44 }
45
46 }
47 // END SNIPPET: configExample