Hi,
I am using AES Implementation.
I am having a large data string.
I am unable to encrypt full data.
pls help me.
urgent.
It is going to be difficult to help you when you have not taken the trouble to post your program and explain what is actually does and what you want it to do.
...R
Ok...
I am having the code snippet like this:
#include <AESLib.h>
void setup()
{
Serial.begin(57600);
uint8_t key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
uint8_t iv[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
char data[] = "aswertyg349838958390304r0324023-40-320-403-04-324r=-324=r-32=-4=32-r=423-=";
aes128_enc_single(key, data);
Serial.print("encrypted:");
Serial.println(data);
aes128_dec_single(key, data);
Serial.print("decrypted:");
Serial.println(data);
}
and my output is like this:
encrypted:òRbŠdG¸˜–?ƒ¾ðÁ¨<8390304r0324023-40-320-403-04-324r=-324=r-32=-4=32-r=423-=
decrypted:aswertyg349838958390304r0324023-40-320-403-04-324r=-324=r-32=-4=32-r=423-=
Conclusion: Only some part of data is encrypted..
Remedies: I understood that the function aes128_enc_single(key, data); will only encrypt 128 bit data , not a whole data which lis large.
Please explain how to use the other function aes128_cbc_enc(key, iv, data, 128);
Please explain how to use the other function aes128_cbc_enc(key, iv, data, 128);
What does the documentation tell you to do?
I was unable to use the function, declaring iv and all other parameters in the function.
Please give me a link(Manual) that tells this concept.
I am new to this.
-
Always post your REAL code in code tags
-
Read the forum posting rules
-
All ways post your REAL results
-
That code did not produce those results
-
Always provide aat least a link to the lib you used
Your answer will be found in the doc's that you did nor read that go with the lib you did not provide a link to
Read the docs and you will see the error (or the wiki for AES)
Mark
- The code is real code which I have used.
- the lib I am using is :
AESLib-master.zip (56.2 KB)
In other way,
pls give a code snippet that works for encrypting large data:
The example data is:
char data[]="012345670123456701234567-&6^&()!012345670123456701234567-&6^&()!012345670123456701234567-&6^&()!012345670123456701234567-&6^&()!012345670123456701234567-&6^&()!012345670123456701234567-&6^&()!012345670123456701234567-&6^&()!012345670123456701234567-&6^&()!012345670123456701234567-&6^&()!012345670123456701234567-&6^&()!012345670123456701234567-&6^&()!012345670123456701234567-&6^&()!";
Note:
-
Pls provide a necessary code snippet & Library.
-
In my project I am having data to be encrypted is of size atleast 700 Characters(700*8=5600 bits).
Read the instructions BEFORE posting.
You must write the code after all it's your home work!
This
aes128_dec_single(key, data);
and this
Only some part of data is encrypted..
give you the answer
Mark
dutt060587:
...
2. In my project I am having data to be encrypted is of size atleast 700 Characters(700*8=5600 bits).
Hi dutt060587. Have you thought about copying data[] 16 bytes at a time into a temporary buffer and then calling aes128_enc_single() with that. It's just a matter or repeating that operation until you have completed the entire data[] string.
You mean to say that I shall have to use a for loop as below:
len=strlen(data);
for(i=0; i<=len; i++)
{
aes128_enc_single(key, data);
}
//something like this:::????
Hint There is no need to copy!
@op No of course that will not work!
Mark
holmes4:
Hint There is no need to copy!
Good point :). You're right, you can do it in place without any problems.
dutt060587, when you write aes128_enc_single(key, data), do you understand that it only passes the base address of data[] (that is, the address of data[0])to the encryption function. The encryption function knows however that it is to use just the first 16 bytes, data[0]..data[15].
Think about what might happen if you passed it data+16, or data + 16*sizeof(char) instead of just data.
Hi,
Welcome to the forum.
This what everybody is asking you to do.
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
What is AES?
Thanks.. Tom..
#include <AESLib.h>
void setup()
{
Serial.begin(57600);
uint8_t key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
char data[]="0123456701234567";
char data1[]=".Í ™*ºlw½@t{&";
aes128_enc_single(key, data);
Serial.print("encrypted:");
Serial.println(data);
aes128_dec_single(key, data1);
Serial.print("decrypted:");
Serial.println(data1);
}
void loop()
{
// put your main code here, to run repeatedly:
}``
Note:
This is the Code I have used for Initial Testing.
When I have used the data for both encryption and decryption , I have given two data arrays.
First array is data that is to be encrypted.
Second array is already encrypted data for first data.
But when I have printed tow data arrays, they are not same.
Please see the image that is attached.
Just fixing those code tags for you.
#include <AESLib.h>
void setup()
{
Serial.begin(57600);
uint8_t key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
char data[]="0123456701234567";
char data1[]=".Í™*ºlw½@t{&";
aes128_enc_single(key, data);
Serial.print("encrypted:");
Serial.println(data);
aes128_dec_single(key, data1);
Serial.print("decrypted:");
Serial.println(data1);
}
void loop()
{
// put your main code here, to run repeatedly:
}
Hi dutt060587. In that code you posted above you are encrypting data[]. but then decryption data1[].
It works properly properly if you just decrypt the actual date you encrypted.
After that modification I get the following output.
encrypted:.Í™*ºlw½@t{&
decrypted:0123456701234567
Yes I understood that, and I do got the same result..
Now my question is:
- When I am increasing the data length what are the changes to be done.?
- Typically my data length would be around 440-500 bytes.
AES is a block mode encryption algorithm with each block being 128 bits (16 bytes). Each block of 16 bytes encrypts to 16 bytes. The simplest approach (this has a number of security flaws that could be exploited by a determined attacker) to encrypting a chunk longer than 16 bytes is to break the chunk into blocks of 16 bytes and to encrypt each block individually.
The obvious problem comes when the chunk length is not a multiple of 16 bytes. Then one has to pad the data in some way so that the chunk length is a multiple of 16 bytes. One can take a simplistic approach and pad with known bytes that can be removed after the cyphertext is decrypted. This works quite well if the padding byte can never be mistaken for the last byte of the chunk. In an ideal world one needs a padding system that can never be ambiguous. There are many of these but one of the most common is PKCS5 (with it's cousin PKCS7). Google will find many references to PKCS5.
If you are serious about cryptography then the 'bible' is "Applied Crytography" by Bruce Schneier with a more practical book being "Practical Cryptography" by Ferguson and Schneier.
As a final note - AES and most modern crytographic algorithms work with bytes and not characters. The resulting cyphertext is also bytes which cannot be displayed using the ASCII character set. If one tries to convert the ciphertext from bytes to characters and back again without thought then one will corrupt the cipher text. Sometimes to be safe one need to code the cyphertext into ASCII characters using something like HEX or Base64 or ASCII85 encoding. These guarantee not to corrupt.
Sir I want changes to be done in code.
Moreover I am having the following constraints.
For a data length of 400-500 Bytes , what may be the
- IV Size,
- Key Size...
- Possible changes in the code given in earlier discussion, Function that I need to use for Encryption & Decryption..?