package com.dayu.henanlibrary.tools; import android.app.Activity; import android.util.Base64; import com.dayu.baselibrary.tools.HexUtil; import com.dayu.baselibrary.tools.nfc.BaseNFCHelper; import java.nio.charset.StandardCharsets; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.SecretKeySpec; /** * author: zuo * Date: 2024-09-26 * Time: 9:30 * 备注: */ public class HNBaseHelper extends BaseNFCHelper { static { System.loadLibrary("henan-native-lib"); } public native String getSafeKey(Object object); /** * 创建该模块的key * * @param activity */ public HNBaseHelper(Activity activity) { // 解密字符串 try { //初始密码 byte[] encryptedBytes = Base64.decode("orDiGzvueQqPpU+VQ3NEzQ==", Base64.DEFAULT); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); 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); defauleKey = HexUtil.hexToByteArray(decryptedText); listKeyA.add(defauleKey); //初始密码 // byte[] encryptedBytes2 = Base64.decode("aYC9feYEOFOQHuzflLIXSw==", Base64.DEFAULT); byte[] encryptedBytes2 = Base64.decode("qeg4DUWf0ni9JfRWtD2krA==", Base64.DEFAULT); byte[] decryptedBytes2 = cipher.doFinal(encryptedBytes2); //decryptedBytes2 对应010203040506 String companyKeyA = new String(decryptedBytes2, StandardCharsets.UTF_8); companyKey = HexUtil.hexToByteArray(companyKeyA); listKeyA.add(companyKey); //修改后的密码 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(); } } }