Is there any AES library supports 'unsigned long' type.How to convert the type

I am making a control system for my computer.You can see my topic at"http://forum.arduino.cc/index.php?topic=184663.0"

I am going to make the encryption based on millis().But many AES library is only support 'byte' type.I am not good at C program.When I use 'byte time=byte(millis());'
serial monitor gaves me some random number.I know that isn't correct.

How to make 'unsigned long' being supported by AES library.Or how to convert it to byte.

By the way.I am confused about byte and char.Are they same?

Halry:
By the way.I am confused about byte and char.Are they same?

One is signed (char), and one isn't.

But byte has 0~255.Signed char only has 0~127

-128 to +127.

How to make 'unsigned long' being supported by AES library.Or how to convert it to byte.

An unsigned long is 4 bytes. Which one are you interested in?

There's a clue up there, in case you missed it.

I just mean I need a AES library support "unsigned long" directly.I am not good at C language. :blush:

If I can't find out how to do it.I have to give it up,because Setp.1 is coming,I need to go to school......

(I make my things for myself using.Not homework......Because in China,no teacher care about your creative.You just need to recite the poem,article.You just need high score....)

I am thinking about the SHA library seems can work with millis().

If you have some good AES library supported 'unsigned long' or you know how to make millis() being encryptable with AES.Please tell me.

I have to make sure the data is true.You can see my post in "I want some idea/library to defense "Replay Attack" for my NRF24L01+Arduino. - Networking, Protocols, and Devices - Arduino Forum"

If no way to get it.I will use SHA256.It will faster than AES.I just want to learn it how to make it.

I want to encrypt millis(),just that.So all bytes I am interested in.

I know 'unsigned long' -> 'char' is not possible to get no damage data.

unsigned long now = millis();

union stuff
{
   long a;
   byte b[4];
};

union stuff encodeThis;
encodeThis.a = now;

aesFun(encodeThis.b);

Here's a few hints. As I said, it isn't rocket science.

Thanks your reply.Get that.I am going to try it.I just don't know too deep about C language.I think I need to study about union/typedef/enum.
Thank you and your code

There is lots of stuff on the Internet about the C language. It is very much in your interest to study it.

PaulS:

unsigned long now = millis();

union stuff
{
   long a;
   byte b[4];
};

union stuff encodeThis;
encodeThis.a = now;

aesFun(encodeThis.b);




Here's a few hints. As I said, it isn't rocket science.

I found that you using a library.aesFun.But I can't found it in google.Can you share this?

So simply write aesFun() yourself, using the libraries you found.

And keep in mind, it takes a 4 bytes binary array as parameter, not a zero delimited char*

Have Fun!

I found that you using a library.aesFun.But I can't found it in google.Can you share this?

Not true. The aesFun() is an example of an AES function that you supposedly already have that takes an array of bytes.

Sorry,I have a problem....

I still can't try to use your code to make AES work.... :blush:

I know union use same RAM area to make this happen..

This code only print once on serial monitor

#include "AES128.h"

byte key[] = { 
  0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 
  0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf 
};
AES128 aes(key);

void setup() {
  Serial.begin(9600);
}

void loop() {
unsigned long now = millis();

union stuff
{
   long a;
   byte b[4];
};

union stuff encodeThis;
encodeThis.a = now;
aes.encrypt(encodeThis.b);
Serial.println("Enc");
Serial.println(encodeThis.a);
}

The AES library from here"https://github.com/una1veritas/Arduino/tree/master/libraries/AES128"
The serial print to me only have

¸g­?o¿yÿc
979576322

Everytime I reset it can get a different print. :cold_sweat: