Permalink
Browse files

加密存储数据库密码

  • Loading branch information...
qiyi committed Dec 9, 2017
1 parent 6221cef commit e0ae89f48eb650157b850dc4f8f186423eeb4ea8
View
10 pom.xml
@@ -19,6 +19,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>4.3.11.RELEASE</spring.version>
<spring.cloud.version>1.2.0.RELEASE</spring.cloud.version>
<junit.jupiter.version>5.0.2</junit.jupiter.version>
<junit.platform.version>1.0.2</junit.platform.version>
</properties>
@@ -60,6 +61,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
<version>${spring.cloud.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
@@ -102,8 +108,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>1.9</source>
<target>1.9</target>
</configuration>
</plugin>
<plugin>
@@ -4,9 +4,14 @@
import com.momo.pink.todo.TodoConfiguration;
import org.apache.ibatis.annotations.Mapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.StandardEnvironment;
import java.util.Map;
@SpringBootApplication
@Import({
@@ -15,8 +20,16 @@
})
@MapperScan(annotationClass = Mapper.class, value = "com.momo.pink")
public class PinkApp {
public static void main(String[] args) {
System.setProperty("spring.jackson.serialization.write_dates_as_timestamps", "false");
SpringApplication.run(PinkApp.class, args);
StandardEnvironment env = new StandardEnvironment();
MutablePropertySources propertySources = env.getPropertySources();
propertySources.addLast(new MapPropertySource("encrypt", Map.of(
"encrypt.key", "${encrypt.rootKey}oUzxewPh"))); //naN8cE/CoUzxewPh
new SpringApplicationBuilder(PinkApp.class)
.properties("spring.jackson.serialization.write_dates_as_timestamps", "false")
.environment(env)
.build()
.run(args);
}
}
@@ -1,3 +1,3 @@
spring.datasource.url=jdbc:mysql://localhost:3306/pink?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=pink
spring.datasource.password=pink
spring.datasource.password={cipher}fb748dce88b94fb7d84a9f32e6b5d51729049792d1ee38e2240b176ec5db91cb
@@ -0,0 +1 @@
encrypt.rootKey=naN8cE/C

0 comments on commit e0ae89f

Please sign in to comment.