From 2de6f42a1657966ad60be3ce7be0831912121fb2 Mon Sep 17 00:00:00 2001 From: pengqiang <1067496116@qq.com> Date: Mon, 6 Dec 2021 14:49:29 +0800 Subject: [PATCH] =?UTF-8?q?sonar=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/palmte/work/shiro/ShiroConfig.java | 1 - .../cn/palmte/work/utils/Base64Utils.java | 37 +++++++++---------- .../java/cn/palmte/work/utils/DESCrypto.java | 22 +---------- 3 files changed, 20 insertions(+), 40 deletions(-) diff --git a/src/main/java/cn/palmte/work/shiro/ShiroConfig.java b/src/main/java/cn/palmte/work/shiro/ShiroConfig.java index b80c5ca..c9fe935 100644 --- a/src/main/java/cn/palmte/work/shiro/ShiroConfig.java +++ b/src/main/java/cn/palmte/work/shiro/ShiroConfig.java @@ -136,7 +136,6 @@ public class ShiroConfig { map.put("/jqPaginator/**", "anon"); map.put("/layer/**", "anon"); map.put("/ueditor/**", "anon"); - map.put("/favicon.png", "anon"); // map.put("/admin/login", "authc"); diff --git a/src/main/java/cn/palmte/work/utils/Base64Utils.java b/src/main/java/cn/palmte/work/utils/Base64Utils.java index 79d11a2..8f40498 100644 --- a/src/main/java/cn/palmte/work/utils/Base64Utils.java +++ b/src/main/java/cn/palmte/work/utils/Base64Utils.java @@ -61,17 +61,17 @@ public class Base64Utils { byte[] data = new byte[0]; File file = new File(filePath); if (file.exists()) { - FileInputStream in = new FileInputStream(file); - ByteArrayOutputStream out = new ByteArrayOutputStream(2048); - byte[] cache = new byte[CACHE_SIZE]; - int nRead = 0; - while ((nRead = in.read(cache)) != -1) { - out.write(cache, 0, nRead); - out.flush(); + try( FileInputStream in = new FileInputStream(file); + ByteArrayOutputStream out = new ByteArrayOutputStream(2048)) { + + byte[] cache = new byte[CACHE_SIZE]; + int nRead = 0; + while ((nRead = in.read(cache)) != -1) { + out.write(cache, 0, nRead); + out.flush(); + } + data = out.toByteArray(); } - out.close(); - in.close(); - data = out.toByteArray(); } return data; } @@ -83,21 +83,20 @@ public class Base64Utils { * @param filePath 文件生成目录 */ public static void byteArrayToFile(byte[] bytes, String filePath) throws Exception { - InputStream in = new ByteArrayInputStream(bytes); File destFile = new File(filePath); if (!destFile.getParentFile().exists()) { destFile.getParentFile().mkdirs(); } destFile.createNewFile(); - OutputStream out = new FileOutputStream(destFile); - byte[] cache = new byte[CACHE_SIZE]; - int nRead = 0; - while ((nRead = in.read(cache)) != -1) { - out.write(cache, 0, nRead); - out.flush(); + try(InputStream in = new ByteArrayInputStream(bytes); + OutputStream out = new FileOutputStream(destFile)){ + byte[] cache = new byte[CACHE_SIZE]; + int nRead = 0; + while ((nRead = in.read(cache)) != -1) { + out.write(cache, 0, nRead); + out.flush(); + } } - out.close(); - in.close(); } } diff --git a/src/main/java/cn/palmte/work/utils/DESCrypto.java b/src/main/java/cn/palmte/work/utils/DESCrypto.java index 0d9b411..34cb96f 100644 --- a/src/main/java/cn/palmte/work/utils/DESCrypto.java +++ b/src/main/java/cn/palmte/work/utils/DESCrypto.java @@ -2,7 +2,8 @@ package cn.palmte.work.utils; import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.digest.DigestUtils; -import sun.misc.BASE64Encoder; + + import javax.crypto.Cipher; import javax.crypto.SecretKey; @@ -51,22 +52,6 @@ public class DESCrypto { return digest; } - // public static void main(String[] args) throws Exception{ -// String key = "VBZ0NR"; -// String value = "dzgadmin0.123456789.!@#$%^&*()"; -// -// byte[] bytes = value.getBytes(encoding); -// String newKey = string2MD5(key).substring(0, 8).toUpperCase(); -// String a = toHexString(encrypt(bytes, newKey)).toUpperCase(); -// System.out.println("加密后的数据为:" + a); -// -// String b = java.net.URLDecoder.decode(decrypt(a, newKey), encoding); -// System.out.println("解密后的数据:" + b); -// -// String res = encryptPassword(value, key); -// -// System.out.println("res:" + res); - // } public static String encryptPassword(String password, String key) throws Exception{ byte[] bytes = password.getBytes(encoding); @@ -114,9 +99,6 @@ public class DESCrypto { } - public static String encryptZSK(String data) throws Exception{ - return new BASE64Encoder().encode(encryptZSK(data.getBytes(), "zhangshangweike0".getBytes())); - } private static byte[] encryptZSK(byte[] data, byte[] key) throws Exception{ // 生成一个可信任的随机数源