左晓为主开发手持机充值管理机
zuoxiao
6 天以前 c3edd4a3122b711bc6a0bfef56b6ff6bf5ae03e2
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
package com.dayu.general.tool
 
import android.content.Context
import com.dayu.baselibrary.tools.HexUtil
import com.dayu.baselibrary.tools.nfc.BaseNFCHelper
 
open class GeBaseHelper(private val context: Context) : BaseNFCHelper() {
 
    companion object {
        init {
            try {
                System.loadLibrary("general-native-lib")
            } catch (e: UnsatisfiedLinkError) {
                e.printStackTrace()
            }
        }
    }
 
    private external fun getM1SectorKeySecure(context: Context, sectorIndex: Int): String
 
    init {
        if(listA_PS.isEmpty()){
            try {
                // 获取所有扇区密钥
                val allKeys: String = getM1SectorKeySecure(context, 0)
                if (allKeys.isNotEmpty()) {
                    val keys: Array<String> = allKeys.split(",").dropLastWhile { it.isEmpty() }.toTypedArray()
                    for (i in keys.indices) {
                        val key = keys[i]
                        if (key.isNotEmpty()) {
                            listA_PS.add(HexUtil.hexToByteArray(key))
                        }
                    }
                }
                defauleKey = HexUtil.hexToByteArray("FFFFFFFFFFFF")
            } catch (e: Exception) {
                e.printStackTrace()
                // 设置默认密钥
                defauleKey = HexUtil.hexToByteArray("FFFFFFFFFFFF")
            }
        }
    }
 
    fun getKeyList(): List<ByteArray> {
        return listA_PS
    }
}