DESFire认证解密 [英] DESFire authentification decipher
问题描述
我正在使用DESFire EV1非接触式卡。
我试图用masterkey解密一个DES / CBC加密的random_b:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00。
I am currently working with DESFire EV1 contactless cards. I am trying to decipher a DES/CBC enciphered random_b with masterkey: "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00".
我使用这个代码:
byte[] encipheredCodeRandomB = { (byte)0xEA ,(byte)0x18 ,(byte)0xDE ,(byte)0xFF
,(byte)0x52 ,(byte)0x0E,(byte)0xCD, (byte) 90};
byte[] masterKeyBytes = "0000000000000000".getBytes();
byte[] ivBytes = "00000000".getBytes();
DESKeySpec desKeySpec = new DESKeySpec(masterKeyBytes);
SecretKeyFactory desKeyFact = SecretKeyFactory.getInstance("DES");
SecretKey s = desKeyFact.generateSecret(desKeySpec);
aliceCipher = Cipher.getInstance("DES/CBC/NoPadding");
aliceCipher.init(Cipher.DECRYPT_MODE, s, new IvParameterSpec(ivBytes));
byte[] decipheredCodeRandomB = aliceCipher.doFinal(encipheredCodeRandomB);
但这段代码不会正确解密。我得到这个无效的结果:4B 9D 5A 91 AE 93 F8 ED正确的是:A4 2F 3E 84 2C 5A 29 68
but this code doesnt decipher correctly. Im getting this invalid result: "4B 9D 5A 91 AE 93 F8 ED" the correct one is: "A4 2F 3E 84 2C 5A 29 68"
推荐答案
如果您的主密钥字节全部为零,则这是不正确的:
If your master key bytes are meant to be all zeroes, then this is incorrect:
byte[] masterKeyBytes = "0000000000000000".getBytes();
这将为您提供平台默认编码中的0000000000000000的文本编码形式 - 最有可能 {0x30,0x30,0x30 ...}
That will get you the text-encoded form of "0000000000000000" in the platform default encoding - most likely { 0x30, 0x30, 0x30 ... }
将数组填满为零很简单: p>
Getting an array full of zeroes is simple though:
byte[] masterKeyBytes = new byte[16];
同样的IV(当然是适当的长度)。
Ditto for the IV (with the appropriate length, of course).
仍然没有给你你想要的结果,诚然...但是它使用全零键/ IV。
That still doesn't give you the result you're looking for, admittedly... but it is using an "all zeroes" key/IV.
这篇关于DESFire认证解密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!