[英]I got 0x9E parameter error while Credit value file on DESFire card
我現在使用DESFire卡上的有價文件。 我使用以下命令在DESFire卡中創建了一個值文件:
byte[] cmdCreateValueFile = new byte[]{
//cmd
(byte)0xCC,
//file no
(byte)0x01,
//com.sett.
(byte)0x00 ,
//access rights
(byte)0x44 , (byte)0x44,
//lower limit
(byte)0x00 ,(byte)0x00 ,(byte)0x00 ,(byte)0x00 ,
//upper limit
(byte)0x00 ,(byte)0x0F ,(byte)0x42 ,(byte)0x40 ,
//initial value
(byte)0x00 ,(byte)0x00 ,(byte)0x00 ,(byte)0x00 ,
//limited credit enabled
(byte)0x00
};
然后,我使用以下命令將文件的值記入貸方:
//select my app first
...
doAuthenticate(); //authenticate with key #4 of my application
//credit in value file
tagResponse_cmdcredit = isodep.transceive(Utils.wrapMessage(
(byte)0x0C, new byte[]{(byte) 0x01 ,
//data
(byte)0x00,(byte)0x00, (byte)0x03 , (byte)0xE8}));
Log.d("credittttttttttt", "111 "+Utils.bytesToHex(tagResponse_cmdcredit));
//do commit transaction
tagResponse_cmdCommitTransaction = isodep.transceive(Utils.wrapMessage(
(byte)0xC7, null));
Log.d("committtttttttt", "111 "+Utils.bytesToHex(tagResponse_cmdCommitTransaction));
我的wrapMessage幫助器方法如下所示:
public static byte[] wrapMessage (byte command, byte[] parameters) throws Exception {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
stream.write((byte) 0x90);
stream.write(command);
stream.write((byte) 0x00);
stream.write((byte) 0x00);
if (parameters != null) {
stream.write((byte) parameters.length);
stream.write(parameters);
}
stream.write((byte) 0x00);
byte[] b = stream.toByteArray();
return b;
}
但是我收到91 9E
錯誤。 可能是什么問題呢?
編輯:我發現了我的錯誤! 我沒有在創建值文件命令中注意MSB和LSB值的初始化。 如果下限為0x00 0x00 0x00 0x00 (零),上限為0x0F 0x42 0x40 (1000 000),則必須這樣:
tagResponse_cmdcreateValueFile = isodep.transceive(Utils.wrapMessage((byte)0xCC, new byte[]{(byte)0x01,
//com.sett.
(byte)0x00 ,
//access rights
(byte)0x44 , (byte)0x44,
//lower limit
(byte)0x00 ,(byte)0x00 ,(byte)0x00 ,(byte)0x00 ,
//upper limit
(byte)0x40 ,(byte)0x42 ,(byte)0x0F ,(byte)0x00 ,
//initial value
(byte)0x00 ,(byte)0x00 ,(byte)0x00 ,(byte)0x00 ,
//limited credit enabled
(byte)0x00}));
我發現了我的錯誤! 根據DESFire文檔,該值始終始終以LSB表示。
例如,當我想貸入1000時,我需要通過
(byte)0xE8, (byte)0x03, (byte)0x00, (byte)0x00
命令而不是0x00 0x00 0x03 0xE8
(其中03E8
是十進制的1000)。 首先使用MSB傳遞值時,這將導致十進制值-402456576(帶符號的4字節整數),該值將超出上限。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.