Skip to content

Commit

Permalink
Merge pull request #55 from CMIPT/kaiser-crud
Browse files Browse the repository at this point in the history
Finish adding salt for password encryption.
  • Loading branch information
Kaiser-Yang authored Sep 26, 2024
2 parents 0f40356 + 5d2ae09 commit 831c5ce
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@
| `frontEndUrl` | `string` | `"http://localhost:3000"` | 前端地址。 |
| `deleteGitUser` | `bool` | `true` | 清理时是否删除 `git` 用户。 |
| `deleteServiceUser` | `bool` | `true` | 清理时是否删除 `service` 用户。 |
| `md5Salt` | `string` | `""` | `MD5` 加密盐值。 |
3 changes: 2 additions & 1 deletion config_default.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@
"druidLoginPassword": "druid",
"frontEndUrl": "http://localhost:3000",
"deleteGitUser": true,
"deleteServiceUser": true
"deleteServiceUser": true,
"md5Salt": ""
}
1 change: 1 addition & 0 deletions script/deploy_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ def write_other_config(config):
"gitHomeDirectory": "git.home.directory",
"gitRepositoryDirectory": "git.repository.directory",
"gitRepositorySuffix": "git.repository.suffix",
"md5Salt": "md5.salt",
}
try:
with open(application_config_file_path, 'a') as f:
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/edu/cmipt/gcs/util/MD5Converter.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
package edu.cmipt.gcs.util;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

@Component
public class MD5Converter {
private static String MD5_SALT;

@Value("${md5.salt}")
public void setMD5Salt(String salt) {
MD5_SALT = salt;
}

public static String convertToMD5(String input) {
try {
byte[] hashBytes = MessageDigest.getInstance("MD5").digest(input.getBytes());
byte[] hashBytes =
MessageDigest.getInstance("MD5")
.digest(
new StringBuilder(input)
.append(MD5_SALT)
.toString()
.getBytes());
StringBuilder hexString = new StringBuilder();
for (byte b : hashBytes) {
String hex = Integer.toHexString(0xff & b);
Expand Down

0 comments on commit 831c5ce

Please sign in to comment.