左晓为主开发手持机充值管理机
zuoxiao
2024-07-29 fc1ec55e6ad56dc92737657750bcca7ed49f53eb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package com.dayu.qiheonlinelibrary.tools;
 
import android.app.Activity;
import android.util.Base64;
 
import com.dayu.baselibrary.tools.HexUtil;
 
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;
 
/**
 * Copyright (C), 2023,
 * Author: zuo
 * Date: 2023-11-09 11:52
 * Description:
 */
public class BaseNFCHelper {
    /**
     * 默认密码(白卡密码)ffffffffffff
     */
    public byte[] defauleKey;
 
    /**
     * 公司密码
     */
    public byte[] companyKey;
    //密码a区
    String companyKeyA;
    //密码B区
    String companyKeyB;
 
 
    static {
        System.loadLibrary("qihealone-native-lib");
    }
 
    public native String getSafeKey(Object object);
 
    public BaseNFCHelper(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);
            //初始密码
//             byte[] encryptedBytes2 = Base64.decode("aYC9feYEOFOQHuzflLIXSw==", Base64.DEFAULT);
            //010203:qeg4DUWf0ni9JfRWtD2krA==
            byte[] encryptedBytes2 = Base64.decode("Zro4j8QP6yjYEA6HtSSNOw==", 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();
        }
    }
}