From fe79cc8b05637b7dd3fc8f4c37a54e5f85da1efc Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期三, 27 三月 2024 17:35:27 +0800
Subject: [PATCH] 优化卡标识设置界面提示

---
 app/src/main/java/com/dayu/recharge/tools/BaseNFCHelper.java |   58 +++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 43 insertions(+), 15 deletions(-)

diff --git a/app/src/main/java/com/dayu/recharge/tools/BaseNFCHelper.java b/app/src/main/java/com/dayu/recharge/tools/BaseNFCHelper.java
index 77e1c11..342e41b 100644
--- a/app/src/main/java/com/dayu/recharge/tools/BaseNFCHelper.java
+++ b/app/src/main/java/com/dayu/recharge/tools/BaseNFCHelper.java
@@ -1,5 +1,6 @@
 package com.dayu.recharge.tools;
 
+import android.app.Activity;
 import android.util.Base64;
 
 import java.nio.charset.StandardCharsets;
@@ -20,30 +21,57 @@
  */
 public class BaseNFCHelper {
     /**
-     * 榛樿瀵嗙爜
+     * 榛樿瀵嗙爜锛堢櫧鍗″瘑鐮侊級ffffffffffff
      */
-    public byte[] bytes;
+    public byte[] defauleKey;
 
-    public BaseNFCHelper() {
+    /**
+     * 鍏徃瀵嗙爜
+     */
+    public byte[] companyKey;
+    //瀵嗙爜a鍖�
+    String companyKeyA;
+    //瀵嗙爜B鍖�
+    String companyKeyB;
+
+
+    static {
+        System.loadLibrary("native-lib");
+    }
+
+    public native String getSafeKey(Object object);
+
+    public BaseNFCHelper(Activity activity) {
         // 瑙e瘑瀛楃涓�
         try {
+            //鍒濆瀵嗙爜
             byte[] encryptedBytes = Base64.decode("orDiGzvueQqPpU+VQ3NEzQ==", Base64.DEFAULT);
             Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
-            byte[] encodedKey = {-117, -104, -100, 84, 111, -102, -29, -21, 72, -82, -105, 123, 77, 79, 17, -55, -102, -28, 50, 23, 67, 98, 0, -96, -10, -48, -60, 81, 113, 80, -32, -26};
+            String data = getSafeKey(activity);
+            byte[] encodedKey = HexUtil.hexToByteArray(data);
+//            byte[] encodedKey = {-117, -104, -100, 84, 111, -102, -29, -21, 72, -82, -105, 123, 77, 79, 17, -55, -102, -28, 50, 23, 67, 98, 0, -96, -10, -48, -60, 81, 113, 80, -32, -26};
             cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(encodedKey, "AES"));
             byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
             String decryptedText = new String(decryptedBytes, StandardCharsets.UTF_8);
-            bytes = HexUtil.hexToByteArray(decryptedText);
-        } catch (NoSuchAlgorithmException e) {
-            throw new RuntimeException(e);
-        } catch (NoSuchPaddingException e) {
-            throw new RuntimeException(e);
-        } catch (InvalidKeyException e) {
-            throw new RuntimeException(e);
-        } catch (BadPaddingException e) {
-            throw new RuntimeException(e);
-        } catch (IllegalBlockSizeException e) {
-            throw new RuntimeException(e);
+            defauleKey = HexUtil.hexToByteArray(decryptedText);
+            //鍒濆瀵嗙爜
+//             byte[] encryptedBytes2 = Base64.decode("aYC9feYEOFOQHuzflLIXSw==", Base64.DEFAULT);
+            byte[] encryptedBytes2 = Base64.decode("qeg4DUWf0ni9JfRWtD2krA==", Base64.DEFAULT);
+            byte[] decryptedBytes2 = cipher.doFinal(encryptedBytes2);
+            //decryptedBytes2 瀵瑰簲010203040506
+            companyKeyA = new String(decryptedBytes2, StandardCharsets.UTF_8);
+            companyKey = HexUtil.hexToByteArray(companyKeyA);
+
+            //淇敼鍚庣殑瀵嗙爜
+            byte[] encryptedBytes3 = Base64.decode("n+SSZFb4DHsreVav/Z5ftg==", Base64.DEFAULT);
+            byte[] decryptedBytes3 = cipher.doFinal(encryptedBytes3);
+            //decryptedBytes3 瀵瑰簲202311202048
+            companyKeyB = new String(decryptedBytes2, StandardCharsets.UTF_8);
+
+
+        } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException |
+                 BadPaddingException | IllegalBlockSizeException e) {
+            e.printStackTrace();
         }
     }
 }

--
Gitblit v1.8.0