@johnwasser also tried assigning different keys for each block. Still the same problem.
Try making all of the arrays 16 bytes. AES128 is a block cipher and always encodes/decodes 16 bytes at a time. I suspect one encryption or decryption is going off the end of your arrays and corrupting the other.
Yep that worked. Thank you so much!
This also means I cannot encrypt a string longer then 16 characters?
You can encrypt multiple blocks. I expect there is an example of that with the library.
New problem i'm facing is that i can only decrypt correctly when i encrypt then decrypt in the same code without interruption. For example I write and read from the tag no problem. But if I write then upload only the reading code it doesn't decrypt at all. Is it maybe because it is not recognizing what the cypher is?
SInce the cypher is defined in the encryption
I don't understand what you mean by that. You encrypt some data and write it to an RFID card. Later you read the encrypted data from the RFID card and decrypt it with the same key. Does that not work?
When you read from the card are you getting back the same 16 bytes that you wrote? Try printing out the 16 bytes in hex sort of like this:
for (int i=0; i< 16; i++)
{
Serial.print(cyphertext[i], HEX);
Serial.print(' ');
}
Serial.println();
Print it to before you write it to the card and after you read it back from the card.
Exactly! I printed the cypher:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
I solved it by adding this line again in the reading function so that it knows what the cypher is and it worked. So I just have to encrypt again before reading. Not very clean but does the job.
aes128.encryptBlock(SSID_cypher, SSID_plaintext);//cypher->output block and plaintext->input block
Cypher becomes:
BB E2 55 3A C6 D8 F1 93 72 87 9A 81 1B 34 4 86
BB E2 55 3A C6 D8 F1 93 72 87 9A 81 1B 34 4 86
BB E2 55 3A C6 D8 F1 93 72 87 9A 81 1B 34 4 86
BB E2 55 3A C6 D8 F1 93 72 87 9A 81 1B 34 4 86
BB E2 55 3A C6 D8 F1 93 72 87 9A 81 1B 34 4 86
BB E2 55 3A C6 D8 F1 93 72 87 9A 81 1B 34 4 86
BB E2 55 3A C6 D8 F1 93 72 87 9A 81 1B 34 4 86
BB E2 55 3A C6 D8 F1 93 72 87 9A 81 1B 34 4 86
BB E2 55 3A C6 D8 F1 93 72 87 9A 81 1B 34 4 86
BB E2 55 3A C6 D8 F1 93 72 87 9A 81 1B 34 4 86
BB E2 55 3A C6 D8 F1 93 72 87 9A 81 1B 34 4 86
BB E2 55 3A C6 D8 F1 93 72 87 9A 81 1B 34 4 86
BB E2 55 3A C6 D8 F1 93 72 87 9A 81 1B 34 4 86
BB E2 55 3A C6 D8 F1 93 72 87 9A 81 1B 34 4 86
BB E2 55 3A C6 D8 F1 93 72 87 9A 81 1B 34 4 86
BB E2 55 3A C6 D8 F1 93 72 87 9A 81 1B 34 4 86
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.