pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

如何解密從 Mifare Desfire EV1 發送的第一條消息

How to decrypt the first message sent from Mifare Desfire EV1(如何解密從 Mifare Desfire EV1 發送的第一條消息)
本文介紹了如何解密從 Mifare Desfire EV1 發送的第一條消息的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

有沒有人知道如何解密從卡發送的第一條消息?我的意思是在身份驗證成功之后,然后您發送一個命令(例如 0x51 (GetRealTagUID).它返回 00+random32bits(總是不同).我嘗試使用以下命令對其進行解密:

Does anyone have a clue how to decrypt the first message sent from the card? I mean after the authentication success and then you send a command (for example 0x51 (GetRealTagUID). It returns 00+random32bits (always different). I try to decrypt it with:

        private byte[] decrypt(byte[] raw, byte[] encrypted, byte[] iv)
            throws Exception {
        IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);
        SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
        Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
        cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivParameterSpec);
        byte[] decrypted = cipher.doFinal(encrypted);
        return decrypted;
    }

并用decrypt(sessionKey, response, iv)調用它

And calling it with decrypt(sessionKey, response, iv)

IV = 全零(16 個字節)

IV = all zeros (16 bytes)

response = 0x51 命令后的 32 個隨機位(只是去掉了兩個零)

response = that 32randombits after the 0x51 command (just removed the two zeros)

有人告訴我,IV 在第一次發送命令 (0x51) 后發生了變化.如何生成正確的 IV 來解密該響應?我認為全零是錯誤的,因為解密后的消息總是不同的,同一張卡應該總是相同的.

Someone told me, that the IV changes after the first sent command (0x51). How to generate the right IV for decrypting that response? I think the all zeros is wrong, because the decrypted message is always different and it should be always same with the same card.

-編輯-

應用您的 (Michael Roland) 指令后,解密的響應仍然只是隨機位.這是我的代碼(我認為我做錯了什么):

After applying your (Michael Roland) instructions, the decrypted response is still just random bits. Here is my code (I think I'm doing something wrong):

            byte[] x = encrypt(sessionKey, iv, iv);

            byte[] rx = rotateBitsLeft(x);

            if ((rx[15] & 0x01) == 0x01)
                rx[15] = (byte) (rx[15] ^ 0x87);

            if ((rx[15] & 0x01) == 0x00)
                rx[15] = (byte) (rx[15] ^ 0x01);

            byte[] crc_k1 = rx;

            byte[] rrx = rotateBitsLeft(rx);

            if ((rrx[15] & 0x01) == 0x01)
                rrx[15] = (byte) (rrx[15] ^ 0x87);

            if ((rrx[15] & 0x01) == 0x00)
                rrx[15] = (byte) (rrx[15] ^ 0x01);

            byte[] crc_k2 = rrx;

            byte[] command = { (byte) 0x51, (byte) 0x80, (byte) 0x00,
                    (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
                    (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
                    (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
                    (byte) 0x00 };

            for (int i = 0; i < 16; i++){
                command[i] = (byte) (command[i] ^ crc_k2[i]);
            }

            byte[] iv2 = encrypt(sessionKey, command, iv);

            byte[] RealUID = decrypt(sessionKey, ReadDataParsed, iv2);

            Log.e("RealUID", ByteArrayToHexString(RealUID));

-EDIT3-

仍然返回總是不同的值.我認為問題可能出在此處:

Still returning always different values. I think the problem might lie here:

byte[] iv2 = encrypt(sessionKey, command, iv);

在創建用于解密響應的新 IV 時使用什么 IV?那里全是零.

What IV to use when creating the new IV for decrypting the response? It is all zeros there.

推薦答案

身份驗證后,IV 被重置為全零.當您使用 AES 身份驗證時,您必須為每個后續命令計算 CMAC(即使 CMAC 實際上并未附加到命令中).因此,您的命令的 CMAC 計算將導致正確的 IV 初始化以解碼響應.IE.命令的 CMAC 等于解密響應的 IV.同樣,對于所有進一步的命令,IV 是來自先前加密/CMAC 的最后一個密碼塊.

After authentication, the IV is reset to all-zeros. As you use AES authentication, you then have to calculate the CMAC for every follow-up command (even if CMAC is not actually appended to the command). So the CMAC calculation for your command will lead to correct IV initialization for decoding the response. I.e. the CMAC for the command is equal to the IV for decrypting the response. Similarly, for all further commands, the IV is the last cipher block from the previous encryption/CMAC.

更新:

如何計算 CMAC pad XOR 值

  • 使用會話密鑰(使用零的 IV)加密一個零塊(0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00).-> x[0..15]
  • x[0..15] 向左旋轉一位.-> rx[0..15]
  • 如果最后一位(rx[15] 中的位 0)為 1:xor rx[15]0x86.
  • rx[0..15] 存儲為 crc_k1[0..15].
  • rx[0..15] 向左旋轉一位.-> rrx[0..15]
  • 如果最后一位(rrx[15] 中的位 0)為 1:xor rrx[15]0x86.
  • rrx[0..15] 存儲為 crc_k2[0..15].
  • Encrypt one block of zeros (0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00) with session key (using IV of zeros). -> x[0..15]
  • Rotate x[0..15] one bit to the left. -> rx[0..15]
  • If the last bit (bit 0 in rx[15]) is one: xor rx[15] with 0x86.
  • Store rx[0..15] as crc_k1[0..15].
  • Rotate rx[0..15] one bit to the left. -> rrx[0..15]
  • If the last bit (bit 0 in rrx[15]) is one: xor rrx[15] with 0x86.
  • Store rrx[0..15] as crc_k2[0..15].

如何計算 CMAC

  • 您使用 0x80 0x00 0x00 ... 將命令填充到密碼的塊大小(AES 為 16 字節).如果命令長度與塊大小的倍數匹配,則不添加填充.
  • 對于您的命令 (0x51),如下所示:0x51 0x80 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
  • 如果添加了填充,則將填充命令的最后 16 個字節與 crc_k2[0..15] 進行異或.
  • 如果沒有添加填充,則將命令的最后 16 個字節與 crc_k1[0..15] 進行異或.
  • 使用會話密鑰加密(在發送模式下,即enc(IV xor datablock),前一個塊的密文是新IV)結果.
  • 最后一個區塊的密文是 CMAC 和新的 IV.
  • You pad the command using 0x80 0x00 0x00 ... to the block size of the cipher (16 bytes for AES). If the command length matches a multiple of the block size, no padding is added.
  • For your command (0x51) this would look like: 0x51 0x80 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
  • If padding was added, xor the last 16 bytes of the padded command with crc_k2[0..15].
  • If no padding was added, xor the last 16 bytes of the command with crc_k1[0..15].
  • Encrypt (in send mode, i.e. enc(IV xor datablock), cipher text of previous block is new IV) the result with the session key.
  • The ciphertext of the last block is the CMAC and the new IV.

更新 2:

如何將位向量向左旋轉一位

public void rotateLeft(byte[] data) {
    byte t = (byte)((data[0] >>> 7) & 0x001);
    for (int i = 0; i < (data.length - 1); ++i) {
        data[i] = (byte)(((data[i] << 1) & 0x0FE) | ((data[i + 1] >>> 7) & 0x001));
    }
    data[data.length - 1] = (byte)(((data[data.length - 1] << 1) & 0x0FE) | t);
}

這篇關于如何解密從 Mifare Desfire EV1 發送的第一條消息的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Java Remove Duplicates from an Array?(Java從數組中刪除重復項?)
How to fix Invocation failed Unexpected Response from Server: Unauthorized in Android studio(如何修復調用失敗來自服務器的意外響應:在 Android 工作室中未經授權)
AES encryption, got extra trash characters in decrypted file(AES 加密,解密文件中有多余的垃圾字符)
AES Error: Given final block not properly padded(AES 錯誤:給定的最終塊未正確填充)
Detecting incorrect key using AES/GCM in JAVA(在 JAVA 中使用 AES/GCM 檢測不正確的密鑰)
AES-256-CBC in Java(Java 中的 AES-256-CBC)
主站蜘蛛池模板: 步进电机_agv电机_伺服马达-伺服轮毂电机-和利时电机 | 高铝砖-高铝耐火球-高铝耐火砖生产厂家-价格【荣盛耐材】 | 找培训机构_找学习课程_励普教育 | 沉降天平_沉降粒度仪_液体比重仪-上海方瑞仪器有限公司 | 热工多功能信号校验仪-热电阻热电偶校验仿真仪-金湖虹润仪表 | 冷藏车厂家|冷藏车价格|小型冷藏车|散装饲料车厂家|程力专用汽车股份有限公司销售十二分公司 | 伺服电机维修、驱动器维修「安川|三菱|松下」伺服维修公司-深圳华创益 | 杭州画室_十大画室_白墙画室_杭州美术培训_国美附中培训_附中考前培训_升学率高的画室_美术中考集训美术高考集训基地 | 塑料撕碎机_编织袋撕碎机_废纸撕碎机_生活垃圾撕碎机_废铁破碎机_河南鑫世昌机械制造有限公司 | 河南砖机首页-全自动液压免烧砖机,小型砌块水泥砖机厂家[十年老厂] | 杭州中央空调维修_冷却塔/新风机柜/热水器/锅炉除垢清洗_除垢剂_风机盘管_冷凝器清洗-杭州亿诺能源有限公司 | 篮球地板厂家_舞台木地板品牌_体育运动地板厂家_凯洁地板 | 网站建设-临朐爱采购-抖音运营-山东兆通网络科技 | 光伏家 - 太阳能光伏发电_分布式光伏发电_太阳能光伏网 | 衬氟止回阀_衬氟闸阀_衬氟三通球阀_衬四氟阀门_衬氟阀门厂-浙江利尔多阀门有限公司 | 威客电竞(vk·game)·电子竞技赛事官网 | 昆明网络公司|云南网络公司|昆明网站建设公司|昆明网页设计|云南网站制作|新媒体运营公司|APP开发|小程序研发|尽在昆明奥远科技有限公司 | 首页|专注深圳注册公司,代理记账报税,注册商标代理,工商变更,企业400电话等企业一站式服务-慧用心 | 中式装修设计_全屋定制家具_实木仿古门窗花格厂家-喜迎门 | 上海皓越真空设备有限公司官网-真空炉-真空热压烧结炉-sps放电等离子烧结炉 | 自动螺旋上料机厂家价格-斗式提升机定制-螺杆绞龙输送机-杰凯上料机 | 分轨 | 上传文件,即刻分离人声和伴奏 | 挤塑板-XPS挤塑板-挤塑板设备厂家[襄阳欧格] | 冷库安装厂家_杭州冷库_保鲜库建设-浙江克冷制冷设备有限公司 | 爱佩恒温恒湿测试箱|高低温实验箱|高低温冲击试验箱|冷热冲击试验箱-您身边的模拟环境试验设备技术专家-合作热线:400-6727-800-广东爱佩试验设备有限公司 | 深圳美安可自动化设备有限公司,喷码机,定制喷码机,二维码喷码机,深圳喷码机,纸箱喷码机,东莞喷码机 UV喷码机,日期喷码机,鸡蛋喷码机,管芯喷码机,管内壁喷码机,喷码机厂家 | 企业彩铃制作_移动、联通、电信集团彩铃上传开通_彩铃定制_商务彩铃管理平台-集团彩铃网 | 撕碎机_轮胎破碎机_粉碎机_回收生产线厂家_东莞华达机械有限公司 | 大型冰雕-景区冰雕展制作公司,3D创意设计源头厂家-[赛北冰雕] | 冷却塔减速机器_冷却塔皮带箱维修厂家_凉水塔风机电机更换-广东康明冷却塔厂家 | R507制冷剂,R22/R152a制冷剂厂家-浙江瀚凯制冷科技有限公司 | 开平机_纵剪机厂家_开平机生产厂家|诚信互赢-泰安瑞烨精工机械制造有限公司 | 恒温振荡混匀器-微孔板振荡器厂家-多管涡旋混匀器厂家-合肥艾本森(www.17world.net) | 耐火砖厂家,异形耐火砖-山东瑞耐耐火材料厂 | 广东燎了网络科技有限公司官网-网站建设-珠海网络推广-高端营销型外贸网站建设-珠海专业h5建站公司「了了网」 | 包装机传感器-搅拌站传感器-山东称重传感器厂家-济南泰钦电气 | 葡萄酒灌装机-食用油灌装机-液体肥灌装设备厂家_青州惠联灌装机械 | 双段式高压鼓风机-雕刻机用真空泵-绍兴天晨机械有限公司 | 517瓜水果特产网|一个专注特产好物的网站| 缠绕机|缠绕膜包装机|缠绕包装机-上海晏陵智能设备有限公司 | 多功能真空滤油机_润滑油全自动滤油机_高效真空滤油机价格-重庆润华通驰 |