I'm trying to read/write a Milfare Classic 1k NFC card (supplied from factory) using an ACR122. I can detect the card, but cannot communicate with it.
I have been searching the web for days trying to find any kind of documentation on this (without success).
I know that these cards are encrypted but surely there is a default password or a way to reset the card?
Here's what I have so far:
card.beginSessionWithReply { (result, error) -> Void in
print("Began card session: \(result) \(card.valid) \(card.currentProtocol)");
let aid : [UInt8] = [0xFF, 0x86, 0x00, 0x00, 0x05, 0x01, 0x00, 0x00, 0x0, 0x00];
var data = NSData(bytes: aid, length: aid.count)
card.transmitRequest(data, reply: { (data, error) -> Void in
print("Transmit: data: \(data) error \(error)");
})
data = "Hi".dataUsingEncoding(NSUTF8StringEncoding)!;
card.sendIns(0xFF, p1: 0x00, p2: 0x00, data: data, le: nil, reply: { (data, uint, error) -> Void in
if let e = error {
if (e.code == TKErrorCode.CorruptedData.rawValue) {
print("CorruptedData");
} else {
print("error code: \(error?.code)");
}
}
print("Sendins: reply:\(data) int:\(uint) error:\(error)");
})
}
Output:
["ACS ACR122U"]
Card is valid
ATR: <3b8f8001 804f0ca0 00000306 03000100 0000006a>
Began card session: true true TKSmartCardProtocol(rawValue: 2)
error code: Optional(-2)
Sendins: reply:nil int:0 error:Optional(Error Domain=CryptoTokenKit Code=-2 "(null)")
Transmit: data: Optional(<6300>) error nil
Any suggestions would be great (including any OS X software capable of reading/writing these cards).
I'm not sure about CryptoTokenKit but i'm sure we can use PICC commands according to ACR122 Application Programming Interface to read/write Mifare Cards.
You have to go through following steps.
Load authentication keys to the reader.
Do authentication.
You need to provide which set of blocks to read and provide authentication key for those. For more info on memory structure of Mifare classic 1k please refer to the datasheet here.
Then you can issue read and write APDU commands (can be found of ACR 122 API documentation). Cheers!