From f680d40e5519c02e4357fd94dfa184b9beff815f Mon Sep 17 00:00:00 2001 From: lizhanwei <Dana_Lee1016@126.com> Date: 星期四, 07 五月 2020 16:45:18 +0800 Subject: [PATCH] 编码、调试根据协议格式生成一个二维码,采用des加密、然后Base64编码,调试通过 --- app/src/main/java/safeluck/drive/evaluation/util/Utils.java | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-) diff --git a/app/src/main/java/safeluck/drive/evaluation/util/Utils.java b/app/src/main/java/safeluck/drive/evaluation/util/Utils.java index b93b924..b7e43f5 100644 --- a/app/src/main/java/safeluck/drive/evaluation/util/Utils.java +++ b/app/src/main/java/safeluck/drive/evaluation/util/Utils.java @@ -14,6 +14,7 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.math.BigDecimal; +import java.nio.charset.Charset; import java.security.SecureRandom; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -34,6 +35,7 @@ import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.DESKeySpec; +import javax.crypto.spec.IvParameterSpec; import safeluck.drive.evaluation.bean.Point; @@ -275,6 +277,30 @@ e.printStackTrace(); } return null; + } /** + * 浜岀淮鐮佸姞瀵� + * @param datasource byte[] + * @param password String + * @return byte[] + */ + public static byte[] qrencrypt(byte[] datasource, String password) { + try{ + Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding"); + DESKeySpec desKeySpec = new DESKeySpec(password.getBytes()); + SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); + SecretKey securekey = keyFactory.generateSecret(desKeySpec); + IvParameterSpec desKey = new IvParameterSpec(password.getBytes()); + //鍒涘缓涓�涓瘑鍖欏伐鍘傦紝鐒跺悗鐢ㄥ畠鎶奃ESKeySpec杞崲鎴� + //Cipher瀵硅薄瀹為檯瀹屾垚鍔犲瘑鎿嶄綔 + //鐢ㄥ瘑鍖欏垵濮嬪寲Cipher瀵硅薄 + cipher.init(Cipher.ENCRYPT_MODE, securekey, desKey); + //鐜板湪锛岃幏鍙栨暟鎹苟鍔犲瘑 + //姝e紡鎵ц鍔犲瘑鎿嶄綔 + return cipher.doFinal(datasource); + }catch(Throwable e){ + e.printStackTrace(); + } + return null; } /** * 瑙e瘑 -- Gitblit v1.8.0