Skip to content

Commit a75f893

Browse files
authored
Merge pull request #27 from yinjihuan/encrypt1.1
fix context-path bug
2 parents f86384a + 35a0ab1 commit a75f893

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

encrypt-core/src/main/java/com/cxytiandi/encrypt/springboot/init/ApiEncryptDataInit.java

+6
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ public class ApiEncryptDataInit implements ApplicationContextAware {
4242
*/
4343
public static List<String> requestDecyptUriList = new ArrayList<String>();
4444

45+
private String contextPath;
46+
4547
@Override
4648
public void setApplicationContext(ApplicationContext ctx) throws BeansException {
49+
this.contextPath = ctx.getEnvironment().getProperty("server.servlet.context-path");
4750
Map<String, Object> beanMap = ctx.getBeansWithAnnotation(RestController.class);
4851
initData(beanMap);
4952
beanMap = ctx.getBeansWithAnnotation(Controller.class);
@@ -115,6 +118,9 @@ private String getApiUri(Class<?> clz, Method method) {
115118

116119
}
117120

121+
if (StringUtils.hasText(this.contextPath)) {
122+
return methodType + this.contextPath + uri.toString();
123+
}
118124
return methodType + uri.toString();
119125
}
120126

encrypt-core/src/main/java/com/cxytiandi/encrypt/util/AesEncryptUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static String aesDecryptByBytes(byte[] encryptBytes, String decryptKey) t
3535
Cipher cipher = Cipher.getInstance(ALGORITHMSTR);
3636
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(decryptKey.getBytes(), "AES"));
3737
byte[] decryptBytes = cipher.doFinal(encryptBytes);
38-
return new String(decryptBytes);
38+
return new String(decryptBytes, "utf-8");
3939
}
4040

4141
public static String aesDecrypt(String encryptStr, String decryptKey) throws Exception {

encrypt-springboot-example/src/main/resources/application.properties

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
server.port=8011
2+
#server.servlet.context-path=/example
23
logging.level.com.cxytiandi.encrypt=DEBUG
34

45
spring.freemarker.cache=true

0 commit comments

Comments
 (0)