This commit is contained in:
TheJoKlLa
2020-11-04 00:41:19 +01:00
parent 2049e7eba3
commit 4004413af7
7 changed files with 517 additions and 83 deletions

View File

@ -39,6 +39,17 @@ namespace NFC.Crypto
}
}
/// <summary>
/// Creates Key from String
/// </summary>
/// <param name="key">Key</param>
/// <param name="cipher">Cipher for Key</param>
/// <param name="keyVersion">Version of Key</param>
public CipherKey(string key, CipherType cipher, byte keyVersion) : this(HexConverter.ConvertFromHexString(key), cipher, keyVersion)
{
}
/// <summary>
/// Generates Empty Key
/// </summary>
@ -122,7 +133,7 @@ namespace NFC.Crypto
switch (cipher)
{
case CipherType.TDES:
return 8;
return 16;
case CipherType.TDES_2K:
return 16;
case CipherType.TDES_3K:

View File

@ -7,6 +7,7 @@ using PCSC.Iso7816;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace NFC.Mifare_DESFire
{
@ -879,16 +880,32 @@ namespace NFC.Mifare_DESFire
INS = (byte)APDUInstructions.READ_DATA,
Data = Concatenate(data, offset_byte, length_byte)
};
_Log.DebugFormat("APDU_CMD(cmd_ReadData): {0}", ConvertToHexString(cmd_ReadData.ToArray()));
APDUResponse response = _Card.Transmit(cmd_ReadData);
_Log.DebugFormat("APDU_RES(cmd_ReadData): {0}", ConvertToHexString(response.ToArray()));
APDUResponse response;
List<byte> read_data = new List<byte>();
CheckAPDUResponse(response);
do
{
_Log.DebugFormat("APDU_CMD(cmd_ReadData): {0}", ConvertToHexString(cmd_ReadData.ToArray()));
response = _Card.Transmit(cmd_ReadData);
_Log.DebugFormat("APDU_RES(cmd_ReadData): {0}", ConvertToHexString(response.ToArray()));
if (response.SW1 == 0x91 && response.SW2 == 0xAF)
{
read_data.AddRange(response.Body);
}
else
{
CheckAPDUResponse(response);
}
cmd_ReadData.INS = 0xAF;
} while (response.SW1 == 0x91 && response.SW2 == 0xAF);
_Log.Debug("End ReadData");
return response.Body;
return read_data.ToArray();
}
/// <summary>