Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample for read and write Mifare 1k with KeyA and KeyB #1

Open
ansega opened this issue Oct 23, 2015 · 4 comments
Open

Sample for read and write Mifare 1k with KeyA and KeyB #1

ansega opened this issue Oct 23, 2015 · 4 comments

Comments

@ansega
Copy link

ansega commented Oct 23, 2015

I want to use this project to read and write Mifare 1k cards, I know the values for KeyA and KeyB but I can't find the proper combination to perform the read and write over the card.

There is a way for achieve this, I can't see a sample who uses such values.

I try to put together that but I'm stuck with the order of the actions.

After the card is detected and the card object is filled, I try for sector 9:

From the Card Added Event I have:

this.Card = args.SmartCard.CreateMiFareCard();

Outside the event on a button I want to get the sector to Authenticate with the keys

var sector = Card.GetSector(9);

But the authentication fails with Message:

System.AggregateException: One or more errors occurred. ---> MiFare.Classic.CardLoginException: Unable to login in sector 9 with key A or B
   at MiFare.Classic.Sector.<GetDataBlockInt>d__25.MoveNext() in C:\Users\Oren\Source\Git\MiFareRT\src\MiFare.Shared\Classic\Sector.cs:line 222
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at MiFare.Classic.Sector.set_KeyA(String value) in C:\Users\Oren\Source\Git\MiFareRT\src\MiFare.Shared\Classic\Sector.cs:line 67
   at SpeeronCheckIn.Hardware.CardReadersWriters.Iso14443_PcSc_Implementation.Write(LogMetaDataEntity callerData, String[] text) in C:\Users\Speeron\Documents\SpeeronTemp\TestProjects\EncodersTest\SpeeronCheckIn.Hardware.CardReadersWriters\Iso14443_PcSc_Implementation.cs:line 262
---> (Inner Exception #0) MiFare.Classic.CardLoginException: Unable to login in sector 9 with key A or B
   at MiFare.Classic.Sector.<GetDataBlockInt>d__25.MoveNext() in C:\Users\Oren\Source\Git\MiFareRT\src\MiFare.Shared\Classic\Sector.cs:line 222<---

Looks like I can write the cards and something is missing but I can't find the way, any sugestion to make it work in Mifare 1K?

@kathmann
Copy link

I have exactly the same issue, when trying to write I get the "Unable to login in sector X with key B" on a factory-default Mifare Classic 1K.

Any help?

@dschinnerl
Copy link

Not sure if this is really the problem in your cases but for anyone hitting the same issue... we tested w/ Mifare 1K and 4K cards on a Omnikey 5421 card reader. Our solution was to modify code a bit...

  • LoadKeysTransmissionType.Volatile = 0x20 // needs to be added in Pcsc.cs
  • MifareStandardCommands.cs#LoadKey needs to modified so that LoadKeysTransmissionType. Volatile is used instead of .Plain

HTH

@nicopretorius
Copy link

Not sure if this is really the problem in your cases but for anyone hitting the same issue... we tested w/ Mifare 1K and 4K cards on a Omnikey 5421 card reader. Our solution was to modify code a bit...

  • LoadKeysTransmissionType.Volatile = 0x20 // needs to be added in Pcsc.cs
  • MifareStandardCommands.cs#LoadKey needs to modified so that LoadKeysTransmissionType. Volatile is used instead of .Plain

HTH

Thanks this worked in my case as well.

@Burialarmach
Copy link

Burialarmach commented Mar 3, 2022

Not sure if this is really the problem in your cases but for anyone hitting the same issue... we tested w/ Mifare 1K and 4K cards on a Omnikey 5421 card reader. Our solution was to modify code a bit...

  • LoadKeysTransmissionType.Volatile = 0x20 // needs to be added in Pcsc.cs
  • MifareStandardCommands.cs#LoadKey needs to modified so that LoadKeysTransmissionType. Volatile is used instead of .Plain

HTH
im using a ACR122U and even with this fix i can't write or login in the sector, do the reader really matter?
moreover with other library i could write on card but not on a wrist band what im getting wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants