|
|
|
@ -28,6 +28,7 @@ public class GenerateKeyIml implements IGenerateKey { |
|
|
|
|
static { |
|
|
|
|
Security.addProvider(new BouncyCastleProvider()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static final String SM4_KEY = "D30CCEEC367C55F0E4C7B3BE8207C5DD"; |
|
|
|
|
private static final String ALGORITHM = "AES/ECB/PKCS5Padding"; |
|
|
|
|
|
|
|
|
@ -36,6 +37,7 @@ public class GenerateKeyIml implements IGenerateKey { |
|
|
|
|
String key; |
|
|
|
|
SM4Util sm4Util = new SM4Util(); |
|
|
|
|
try { |
|
|
|
|
// 解密
|
|
|
|
|
String decryptBySM4ECB = sm4Util.decryptBySM4ECB(sm4, SM4_KEY); |
|
|
|
|
Cipher cipher = Cipher.getInstance(ALGORITHM, "BC"); |
|
|
|
|
SecretKeySpec secretKey = new SecretKeySpec(decryptBySM4ECB.getBytes(StandardCharsets.UTF_8), "AES"); |
|
|
|
@ -48,20 +50,12 @@ public class GenerateKeyIml implements IGenerateKey { |
|
|
|
|
} |
|
|
|
|
return key; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static String mapToString(Map<String, String> map) { |
|
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
|
for (Map.Entry<String, String> entry : map.entrySet()) { |
|
|
|
|
sb.append(entry.getKey()).append('=').append(entry.getValue()).append('&'); |
|
|
|
|
} |
|
|
|
|
// public static void main(String[] args) throws IOException {
|
|
|
|
|
// //key为spring.datasource.key的值
|
|
|
|
|
// String key = "D30CCEEC367C55F0E4C7B3BE8207C5DD";
|
|
|
|
|
// SM4Util sm4Util = new SM4Util();
|
|
|
|
|
// String encryptBySM4ECB = sm4Util.encryptBySM4ECB("admin", key);
|
|
|
|
|
// System.out.println(encryptBySM4ECB);
|
|
|
|
|
// String decryptBySM4ECB = sm4Util.decryptBySM4ECB(encryptBySM4ECB, key);
|
|
|
|
|
// System.out.println(decryptBySM4ECB);
|
|
|
|
|
// }
|
|
|
|
|
return sb.toString(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|