| | |
| | | //加密后文件存放位置 |
| | | private static final String ENCRYPT_PATH = "META-INF/" + Const.FILE_NAME + "/"; |
| | | |
| | | //加密后文件存放位置 |
| | | private static final String DESCRIPTION_PATH = "META-INF/"; |
| | | |
| | | /** |
| | | * 单例 |
| | | * |
| | |
| | | } |
| | | |
| | | /** |
| | | * 在jar文件或目录中读取密码字节 |
| | | * |
| | | * @param workDir jar文件或目录 |
| | | * @param name 文件名 |
| | | * @return 文件字节数组 |
| | | */ |
| | | public static byte[] readEncryptedFile2(File workDir, String name) { |
| | | byte[] bytes = null; |
| | | String fileName = DESCRIPTION_PATH + name; |
| | | //jar文件 |
| | | if (workDir.isFile()) { |
| | | bytes = JarUtils.getFileFromJar(workDir, fileName); |
| | | } else {//war解压的目录 |
| | | File file = new File(workDir, fileName); |
| | | if (file.exists()) { |
| | | bytes = IoUtils.readFileToByte(file); |
| | | } |
| | | } |
| | | return bytes; |
| | | } |
| | | |
| | | /** |
| | | * 读取隐藏在jar的密码 |
| | | * |
| | | * @param workDir jar路径 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 读取隐藏在jar的密码 |
| | | * |
| | | * @param workDir jar路径 |
| | | * @return 密码char |
| | | */ |
| | | public static char[] readPassFromJar2(File workDir) { |
| | | byte[] passbyte = readEncryptedFile2(workDir, Const.FILE_NAME2); |
| | | if (passbyte != null) { |
| | | char[] pass = StrUtils.toChars(passbyte); |
| | | return EncryptUtils.md5(pass); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 解密配置文件,spring读取文件时调用 |
| | | * |
| | | * @param path 配置文件路径 |