March 18, 2011

Andre Andre
Robot Herder
6420 posts

New SimpleCrypt page

Page  
1

I have just added a page [developer.qt.nokia.com] in the Snippets category that details a class to deal with some simple encryption and decryption. I would really welcome any comments you may have, on the text of the Wiki page, the API of the class, or the strength of the encryption algorithm used. Note that I am not an expert in cryptography :-)

Would it be useful to add a section discussing the actual algorithm used in the class?

87 replies

March 18, 2011

ZapB ZapB
Ant Farmer
1427 posts

Hi Andre,

nice entry. Thanks for sharing the code.

 Signature 

Nokia Certified Qt Specialist
Interested in hearing about Qt related work

March 18, 2011

Alicemirror Alicemirror
Lab Rat
825 posts

Andre, I think it’s useful.

This kind of cipher as you explain seems simple and efficient, just what a lot of mobile developers needs to give to their applications the option for data to be “unreadable by others”.

I am thinking to those that I am developing: naijanimi (at projects.forum.nokia.com/naijanimi; restricted access) It is at an early stage but I should (to be clear: I SHOULD ;) ) go ahead very fast this next w.e. The encryption capability, not really required by the customer, is missing but needed: it is an application to send free SMS and some data (just user and login, phone number etc) are saved on the phone and if they are encrypted it is best.

Edit: make link into real link, and added note on restricted access to page; Andre

 Signature 

Enrico Miglino (aka Alicemirror)
Tech Consulting
Islas Baleares, Ibiza (Spain)
http://www.contesti.eu

March 20, 2011

Andre Andre
Robot Herder
6420 posts

I am glad people seem to appreciate the snippets I have posted so far.

Andre wrote:
Would it be useful to add a section discussing the actual algorithm used in the class?

Does anyone think it is possible nessecairy to document this in more detail in the article?

March 20, 2011

Alicemirror Alicemirror
Lab Rat
825 posts

Hi Andre, I can if you explain to me a bit more what do yo have in mind. What I am thinking is to use this class in an application that I am building in these days, so the reference code can became a set of snippets for users that want to use, while the application itself can be a usage sample (it is shared on projects.forum.nokia.com/najianimi). The informations can be collected in the wiki integrating the page you have already wrote.

 Signature 

Enrico Miglino (aka Alicemirror)
Tech Consulting
Islas Baleares, Ibiza (Spain)
http://www.contesti.eu

March 20, 2011

Andre Andre
Robot Herder
6420 posts

I’m not sure the page needs a lot of snippets illustrating the use. It seems quite clear to me. Or do you think it needs more examples?

March 20, 2011

Alicemirror Alicemirror
Lab Rat
825 posts

Andre, I was no clear in my thought. The page is clear, as is, with the snippet. I agree that a wiki page with too much code became confusing. What I mean is that integrating your page, with a little more documentation about encryption and a project that can be an example (that use in a precise vode source your class) can be useful.

Usually what I find in documentation on the net regarding encryption or similar, is too much code or too much teory.

 Signature 

Enrico Miglino (aka Alicemirror)
Tech Consulting
Islas Baleares, Ibiza (Spain)
http://www.contesti.eu

March 20, 2011

saidiahd saidiahd
Lab Rat
36 posts

thank you Andre , a very good work

 Signature 

“Learn from yesterday, live for today, hope for tomorrow.” - Albert Einstein -

March 20, 2011

Alicemirror Alicemirror
Lab Rat
825 posts

Sure ! :) It’s a great starting point.

 Signature 

Enrico Miglino (aka Alicemirror)
Tech Consulting
Islas Baleares, Ibiza (Spain)
http://www.contesti.eu

March 21, 2011

Milot Shala Milot Shala
Lab Rat
396 posts

Nice entry Andre.

March 21, 2011

Andre Andre
Robot Herder
6420 posts

I am currently working on a version 2, with these added features:

  • optional integrity checks using a checksum or a cryptographic hash
  • error reporting
  • slightly higher security due to added random character. That should make it harder to guess the first byte of the key based on the fact that there are only a limited number of characters used normally. Should increase effective key length by an guestimated 3 bits.

March 21, 2011

Andre Andre
Robot Herder
6420 posts

I have just uploaded a modified version that implements the above features.

March 21, 2011

Alicemirror Alicemirror
Lab Rat
825 posts

I am waiting in the shade… When I start (hope tomorrow) I can get the last version :)

 Signature 

Enrico Miglino (aka Alicemirror)
Tech Consulting
Islas Baleares, Ibiza (Spain)
http://www.contesti.eu

March 21, 2011

Volker Volker
Ant Farmer
5428 posts

If you miss the documentation tools discussion: I’ve split it out to a new thread [developer.qt.nokia.com]

March 22, 2011

Andre Andre
Robot Herder
6420 posts

I have added a separate page [developer.qt.nokia.com] that details the algorithm and the layout of the cypher text. Of course, I also added a link from the main page.

March 23, 2011

Pau Pau
Lab Rat
25 posts

Hi Andre,
First: Thanks for sharing the code.

Second: You’ve got some typos in the Example usage code.

  • Name of the Class: SimpleCypt —> SimpleCrypt
  • crypto.setCompression(SimpleCrypto::CompressionAlways)
    • crypto.setCompressionMode(SimpleCrypt::CompressionAlways);
  • crypto.setIntegrityProtection(SimpleCrypto::ProtectHash);
    • crypto.setIntegrityProtectionMode(SimpleCrypt::ProtectionHash);
  • SimpleCrypt.ErrorNoError —> SimpleCrypt::ErrorNoError

Third:
The String Encryption and Decryption works fine, but for the binary version I seem to be having some difficulties.

my main.cpp

  1. #include "simplecrypt.h"
  2.  
  3. #include <QString>
  4. #include <QDebug>
  5. #include <QBuffer>
  6. #include <QDataStream>
  7.  
  8. int main(){
  9.  QString txStr = "Hello world!";
  10.  
  11.  SimpleCrypt crypto(Q_UINT64_C(0x7F29B208)); //some random number
  12. // crypto.setCompressionMode(SimpleCrypt::CompressionAlways);
  13. // crypto.setIntegrityProtectionMode(SimpleCrypt::ProtectionHash);  
  14.  QBuffer txB;
  15.  QDataStream s(&txB);
  16.  s << txStr;
  17.  
  18.  QByteArray cypherBytes = crypto.encryptToByteArray(txB.data());
  19.  if (crypto.lastError() == SimpleCrypt::ErrorNoError) {
  20.   qDebug() << cypherBytes;
  21.  }
  22.  
  23.  SimpleCrypt cryptu(Q_UINT64_C(0x7F29B208)); //some random number
  24.  QByteArray plainBytes = cryptu.decryptToByteArray(cypherBytes);
  25.  if (!cryptu.lastError() == SimpleCrypt::ErrorNoError) {
  26.   qDebug() << "decrypt error";
  27.   return 0;
  28.  }
  29.  qDebug() << plainBytes;
  30.  
  31.  QString rxStr;
  32.  QBuffer rxB(&plainBytes);
  33.  QDataStream rs(&rxB);
  34.  rs >> rxStr;
  35.  qDebug() << rxStr;
  36.  return 0;
  37. }

My Output (console):

“??Sß+”
“”
“”

What have I missed or using incorrectly?

Thanks again for the contribution.

Page  
1

  ‹‹ New Qt for Embedded Linux Series started      new DocumentWindow wiki page - How to do this on Linux / Mac? ››

You must log in to post a reply. Not a member yet? Register here!