android - How can I write to a MIFARE Classic tag? -


how can write mifare classic tag?

i have written code, writeblock results in error "java.io.ioexception: transceive failed".

how can solved?

mifareclassic mfc = mifareclassic.get(mytag); boolean auth = false; mfc.connect(); auth = mfc.authenticatesectorwithkeya(1,mifareclassic.key_default); if (auth) {     string text = "hello, world!";     byte[] value  = text.getbytes();     byte[] towrite = new byte[mifareclassic.block_size];              (int i=0; i<mifareclassic.block_size; i++) {         if (i < value.length) towrite[i] = value[i];         else towrite[i] = 0;     }                 mfc.writeblock(2, towrite); } 

first of all, authenticating wrong sector. here, authenticate sector 1 key a:

auth = mfc.authenticatesectorwithkeya(1, mifareclassic.key_default); 

as past if (auth), assume authentication key_defaultas key sector 1 successful.

but then, trying write block 2, in sector 0:

mfc.writeblock(2, towrite); 

as authenticated sector 1, writing sector 0 fail. can write blocks in sector last authenticated to. sector 1, blocks 4 7. note run same problem if authenticate sector 2 , try write block 4 (which in sector 1).

if read comments below post correctly, tried authenticate sector 1 , access block 4 resulting in same error. if case, access conditions of sector 1 prohibit write operations key a.


Comments

Popular posts from this blog

Why can rails not find a route created by a helper? -

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -