Same encryption using c++ symbian & C# .net

Login to reply to this topic.
Tue, 2006-12-05 15:06
Joined: 2006-09-05
Forum posts: 3
Hi all.
I'm developing an application for symbian and it sends data to an internet pc server.
I need to encrypt this data and i'm looking for an encription method common to use.

Trying to use the ported Rijndael code found on internet i discovered a limitation of 32 chars maximum length, while in c# the RijndaelManaged class doesn't have this limitation.
I tried to encrypt a small string of chars:
encryption (symbian) -> decryption (symbian) works fine, but
encryption (symbian) -> decryption (pc) doesn't work.
I'm using the same cipherMode (BCB), same secret key and same Init vector.

Does someone know a tested way to encrypt data in symbian (using c++) and decrypt it in a pc (using c#).

Thank you very much.

Tue, 2006-12-05 17:57
Joined: 2006-08-11
Forum posts: 16
Re: Same encryption using c++ symbian & C# .net
I have not studied the issue. But one thing came to my mind. Can it not be due to different endianness on PC and Symbian HW?
Tue, 2006-12-05 19:45
Joined: 2005-11-20
Forum posts: 1094
Re: Same encryption using c++ symbian & C# .net
How do you transport the data? Is the data binary and the method of transport that you use safe for binary data? It might be that it is not, that one way (from PC to phone) works purely by chance, and the other way (from phone to PC) does not.

Anyway, what's your application? The application usually decides which kind of encryption (weak, strong, very strong) is needed.

René Brunner

Wed, 2006-12-06 12:40
Joined: 2004-11-29
Forum posts: 1142
Re: Same encryption using c++ symbian & C# .net
Rijndael is a block crypto, with 32 byte blocks, that is your "limitation".

Seems your example implementation only handles one block, and you have to do the chaining yourself.

If you encrypt just one block with either pc or symbian version and same key and init vector, your result should be decryptable on both sides.

My guess is that the "managed" version not outputs just the block but some extra header information or such.

Thu, 2006-12-07 11:40
Joined: 2006-09-05
Forum posts: 3
Re: Same encryption using c++ symbian & C# .net
Thank you very much, now i'm trying to use in .net the Rijndael class instead of RijndaelManaged.

rbrunner:
Encrypted data is encoded (Base64) just to avoid binary data format. Then i send it with a socket to a server over the internet.
While in debug i can see the encrypted buffer and i can see that is differend from the same source text encrypted from the pc server program using the RijndaelManaged class of .net
So, i don't think the transport could be the reason....maybe....

alh:
I found on internet that 32 bytes is the real limit os AES encryption ... so it seems you are on the right way...
RijdaelManaged class allow me to encrypt a longer string as surely manage the chaining of encrypted blocks...
As i don't know how this class separates encrypted blocks i think i will have to manage the chaining both in pc and symbian.
Now i will try to use the simple Rijndael class on .net ...
Later i will post the codes (pc and symbian) if i find a working solution.

Thank you very much by now!
Thu, 2006-12-07 13:29
Joined: 2004-11-29
Forum posts: 1142
Re: Same encryption using c++ symbian & C# .net
Its not a "limitation", its just how block cryptos work. They work on fixed size blocks.

If the output from your encryption with the managed class, isn't exactly 32 bytes, or a multiple of it, it means it has some more information in it.

To encrypt more then one block you use some kind of "chaining" wich is to use some information from block 1 to encrypt block 2, some from block 2 to encrypt block 3 etc, this to counter "known plain text" attacks. There are different techniques to do this chaining, where I think CBC is the most common. (havn't fiddled with crypto in a long time so I might be wrong though)

You should read up some on encryption theory, or you are bound to make some small mistakes that breaks the security.
  • Login to reply to this topic.