Hi,, Iam adam.
I am still a newbie in security arduino . I have an example of DES security code with a maximum of 8 characters plaintext input string.
#include <DES.h>
DES des;
void setup() {
Serial.begin(9600);
while (!Serial);
}
void loop() {
desTest();
delay(2000);
}
void desTest()
{
int n;
byte out[16];
byte in[] = ("#N1X5Y6!");
des.calc_size_n_pad(sizeof(in));
byte in_p[des.get_size()];
des.padPlaintext(in,in_p);
byte cyphertext[des.get_size()];
byte key[] = ("TELKOM12");
Serial.println();
Serial.println("========= DES test ==========");
Serial.println("Start");
Serial.print ("Keyword = ");
for (int j=0;j<8;j++){
if (key[j]<0x10) Serial.print("0");
Serial.print(key[j],HEX);Serial.print(" ");
}
Serial.println();
Serial.print ("Plaintext = ");
for (int j=0;j<8;j++){
if (in[j]<0x10) Serial.print("0");
Serial.print(in[j],HEX);Serial.print(" ");
}
Serial.println();
//encrypt
Serial.print("Encrypt...");
unsigned long time = micros();
des.encrypt(out, in, key);
time = micros() - time;
Serial.print("done. (");
Serial.print(time);
Serial.println(" micros)");
printArray(out);
//decrypt
for (int i = 0; i < 8; i++)
{
in = out*;*
* }*
* Serial.print("Decrypt...");*
* time = micros();*
* des.decrypt(out, in, key);*
* time = micros() - time;*
* Serial.print("done. (");*
* Serial.print(time);*
* Serial.println(" micros)");*
* printArray(out);*
}
void printArray(byte output[])
{
* for (int i = 0; i < 8; i++)*
* {*
_ if (output < 0x10)
* {
Serial.print("0");
}
Serial.print(output, HEX);
Serial.print(" ");
}
Serial.println();
}*
I want to try to add padding to the size of the plaintext by using PKCS7. can anyone help me ?
I say thank you very much._