CPU卡與傳統的MifareOne系列卡相比,具有更加安全、複雜的認證機制,這就意味着CPU卡的讀寫操作在軟件開發中變得更加的複雜。我們這些複雜的操作封裝成5個通用的函數,與我們的CPU讀寫器相結合,讓您十分鐘就搞定CPU的讀寫操作。
//'CPU卡尋卡及將卡復位到14443A-4的指令狀態
[DllImport("OUR_MIFARE.dll", EntryPoint = "cpurequest")]
static extern byte cpurequest(byte[] serial, byte[] param, byte[] cosver, byte[] code);
//-----------------------------------------------------------------------------------------------------------------------------
//初始化函數,(ctrlword是否需要先清空卡,不需要清空的話,可以需輸入卡密碼,卡密碼長度)ctrlword_0是否先清空卡,分配空間(字節數),
//Public Declare Function cpursinit Lib "OUR_MIFARE.dll" (ByVal ctrlword As Byte, ByVal key As Long, ByVal keylen As Byte, ByVal customsize As Long) As Byte
[DllImport("OUR_MIFARE.dll", EntryPoint = "cpursinit", CallingConvention = CallingConvention.StdCall)]
static extern byte cpursinit(byte ctrlword, byte[] key, byte[] keylen, Int32 customsize);
//-----------------------------------------------------------------------------------------------------------------------------
//增加文件(文件序號0~5,文件只讀密碼:長度,文件讀寫密碼,長度,分配空間)
//Public Declare Function cpursfileadd Lib "OUR_MIFARE.dll" (ByVal fileno As Byte, ByVal readonlykey As Long, ByVal readonlykeylen As Byte, ByVal writekey As Long, ByVal writekeylen As Byte, ByVal customsize As Long) As Byte
[DllImport("OUR_MIFARE.dll", EntryPoint = "cpursfileadd", CallingConvention = CallingConvention.StdCall)]
static extern byte cpursfileadd(byte fileno, byte[] readonlykey, byte[] readonlykeylen, byte[] writekey, byte[] writekeylen, Int32 customsize);
//-----------------------------------------------------------------------------------------------------------------------------
//'修改文件密碼,修改後,請妥慎記住,否則該文件將無法再用
//Public Declare Function cpursfilekeychg Lib "OUR_MIFARE.dll" (ByVal fileno As Byte, ByVal keytype As Byte, ByVal oldkey As Long, ByVal oldkeylen As Byte, ByVal newkey As Long, ByVal newkeylen As Byte) As Byte
[DllImport("OUR_MIFARE.dll", EntryPoint = "cpursfilekeychg", CallingConvention = CallingConvention.StdCall)]
static extern byte cpursfilekeychg(byte fileno, byte keytype, byte[] oldkey, byte[] oldkeylen, byte[] newkey, byte[] newkeylen);
//-----------------------------------------------------------------------------------------------------------------------------
//'修改卡密碼,卡密碼和文件沒有任何關係,卡密碼只是用來清空卡,讀和寫文件是無效的。
//Public Declare Function cpurscardkeychg Lib "OUR_MIFARE.dll" (ByVal oldkey As Long, ByVal oldkeylen As Byte, ByVal newkey As Long, ByVal newkeylen As Byte) As Byte
[DllImport("OUR_MIFARE.dll", EntryPoint = "cpurscardkeychg", CallingConvention = CallingConvention.StdCall)]
static extern byte cpurscardkeychg(byte fileno, byte[] readonlykey, byte[] readonlykeylen, byte[] writekey, byte[] writekeylen, Int32 customsize);
//-----------------------------------------------------------------------------------------------------------------------------
//讀文件數據(文件序號,讀寫密碼,密碼長度,讀取起始位置,讀取長度,讀出內容)
//Public Declare Function cpursfiledataread Lib "OUR_MIFARE.dll" (ByVal fileno As Byte, ByVal keytype As Byte, ByVal key As Long, ByVal keylen As Byte, ByVal startaddr As Long, ByVal databuf As Long, ByVal datalen As Long) As Byte
[DllImport("OUR_MIFARE.dll", EntryPoint = "cpursfiledataread", CallingConvention = CallingConvention.StdCall)]
static extern byte cpursfiledataread(byte fileno, byte keytype, byte[] rwkey, byte[] rwkeylen, Int32 startaddr, byte[] databuf, Int32 datalen);
//-----------------------------------------------------------------------------------------------------------------------------
//寫文件數據(文件序號,文件讀寫密碼,密碼長度,寫入起始位置,寫入長度,寫入內容)
//Public Declare Function cpursfiledatawrite Lib "OUR_MIFARE.dll" (ByVal fileno As Byte, ByVal keytype As Byte, ByVal key As Long, ByVal keylen As Byte, ByVal startaddr As Long, ByVal databuf As Long, ByVal datalen As Long) As Byte
[DllImport("OUR_MIFARE.dll", EntryPoint = "cpursfiledatawrite", CallingConvention = CallingConvention.StdCall)]
static extern byte cpursfiledatawrite(byte fileno, byte keytype, byte[] rwkey, byte[] rwkeylen, Int32 startaddr, byte[] databuf, Int32 datalen);
//-----------------------------------------------------------------------------------------------------------------------------
//修改卡密碼,卡密碼和文件沒有任何關係,卡密碼只是用來清空卡,讀和寫文件是無效的。
//Public Declare Function cpurscardkeychg Lib "OUR_MIFARE.dll" (ByVal oldkey As Long, ByVal oldkeylen As Byte, ByVal newkey As Long, ByVal newkeylen As Byte) As Byte
[DllImport("OUR_MIFARE.dll", EntryPoint = "cpurscardkeychg", CallingConvention = CallingConvention.StdCall)]
static extern byte cpurscardkeychg(byte[] oldkey, byte[] oldlen, byte[] newkey, byte[] newlen);