0

let say I have an array of character that I want to encrypt using symmetric key. I try to do some research, and I found out that I can use rc4_encrypt function to encrypt and decrypt (I found this function in man page of crypto(3). I try to do something like this:

char* myData = malloc(sizeof(char)*256);
//some code that fill the contain of the array
//encrypt myData
printf("encrypted array: %s", myData);
//decrypt myData
printf("decrypted array: %s", myData);

however, I don't know how can I use that rc4_encrypt function to encrypt and decrypt the array. Do I have to include anything? Can anyone help me? Thanks

eldwin h
  • 57
  • 5
  • ... who's RC4 library are you using? (so we can look at the documentation). – Jacob Pollack Aug 16 '13 at 01:34
  • 1
    Surely the documentation of the `rc4_encrypt` function explains how to use it. – Barmar Aug 16 '13 at 01:35
  • @jacobpollack I found that function in here http://linux.die.net/man/3/crypto – eldwin h Aug 16 '13 at 01:36
  • @eldwinh, found something that may be of some use. See below. – Jacob Pollack Aug 16 '13 at 01:41
  • Using RC4 is frought with danger. For new projects in C I would recommend AES in openssl instead. Try and understand things like block modes and padding modes before you start developing. – Maarten Bodewes Aug 16 '13 at 01:49
  • @owlstead, well it's a school assignment. I try to do some research, but this is the only function that I found. can you point out the documentation of ur recommendation? do you mean something like this one?http://wiki.openssl.org/index.php/EVP_Symmetric_Encryption_and_Decryption – eldwin h Aug 16 '13 at 01:54
  • As a test, try to encrypt with AES in CBC mode and PKCS#7 padding using openssl. There should be plenty examples for that on the internet, [here is a very simple one](http://stackoverflow.com/a/10368443/589259). Don't forget to read the manual pages. PKCS(7) paddding is enabled by default for these slightly higher level functions. – Maarten Bodewes Aug 16 '13 at 01:59

1 Answers1

0

Do I have to include anything?

99% of the time the answer to this is yes. In this specific case, it is no exception -- yes you do.

Can anyone help me?

I can push you in the right direction. From a quick google search I found this. It is a sample implementation of RC4 using their own implementation of the cipher. I am not sure what license it is released under so be careful when using it, however it has everything you need to both learn and implement your own RC4 cipher functionality in C.

Jacob Pollack
  • 3,703
  • 1
  • 17
  • 39
  • so you re saying that I have to implement my own encryption function? I think there is a build in des or aes or rc4 encryption function in linux or c library – eldwin h Aug 16 '13 at 01:47