Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Behind the Scenes
  3. Wiki Discussion
  4. New SimpleCrypt page
Forum Updated to NodeBB v4.3 + New Features

New SimpleCrypt page

Scheduled Pinned Locked Moved Wiki Discussion
98 Posts 26 Posters 96.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • AlicemirrorA Offline
    AlicemirrorA Offline
    Alicemirror
    wrote on last edited by
    #3

    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":projects.forum.nokia.com/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

    Enrico Miglino (aka Alicemirror)
    Balearic Dynamics
    Islas Baleares, Ibiza (Spain)
    www.balearicdynamics.com

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #4

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

      [quote author="Andre" date="1300457411"]Would it be useful to add a section discussing the actual algorithm used in the class?[/quote]

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

      1 Reply Last reply
      0
      • AlicemirrorA Offline
        AlicemirrorA Offline
        Alicemirror
        wrote on last edited by
        #5

        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.

        Enrico Miglino (aka Alicemirror)
        Balearic Dynamics
        Islas Baleares, Ibiza (Spain)
        www.balearicdynamics.com

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #6

          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?

          1 Reply Last reply
          0
          • AlicemirrorA Offline
            AlicemirrorA Offline
            Alicemirror
            wrote on last edited by
            #7

            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.

            Enrico Miglino (aka Alicemirror)
            Balearic Dynamics
            Islas Baleares, Ibiza (Spain)
            www.balearicdynamics.com

            1 Reply Last reply
            0
            • S Offline
              S Offline
              saidiahd
              wrote on last edited by
              #8

              thank you Andre , a very good work

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

              1 Reply Last reply
              0
              • AlicemirrorA Offline
                AlicemirrorA Offline
                Alicemirror
                wrote on last edited by
                #9

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

                Enrico Miglino (aka Alicemirror)
                Balearic Dynamics
                Islas Baleares, Ibiza (Spain)
                www.balearicdynamics.com

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  milot.shala
                  wrote on last edited by
                  #10

                  Nice entry Andre.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #11

                    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.
                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #12

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

                      1 Reply Last reply
                      0
                      • AlicemirrorA Offline
                        AlicemirrorA Offline
                        Alicemirror
                        wrote on last edited by
                        #13

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

                        Enrico Miglino (aka Alicemirror)
                        Balearic Dynamics
                        Islas Baleares, Ibiza (Spain)
                        www.balearicdynamics.com

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          goetz
                          wrote on last edited by
                          #14

                          If you miss the documentation tools discussion: I've split it out to a "new thread":http://developer.qt.nokia.com/forums/viewthread/4619/

                          http://www.catb.org/~esr/faqs/smart-questions.html

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            andre
                            wrote on last edited by
                            #15

                            I have added a "separate page":http://developer.qt.nokia.com/wiki/SimpleCrypt_algorithm_details that details the algorithm and the layout of the cypher text. Of course, I also added a link from the main page.

                            1 Reply Last reply
                            0
                            • P Offline
                              P Offline
                              paucoma
                              wrote on last edited by
                              #16

                              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
                              @
                              #include "simplecrypt.h"

                              #include <QString>
                              #include <QDebug>
                              #include <QBuffer>
                              #include <QDataStream>

                              int main(){
                              QString txStr = "Hello world!";

                              SimpleCrypt crypto(Q_UINT64_C(0x7F29B208)); //some random number
                              // crypto.setCompressionMode(SimpleCrypt::CompressionAlways);
                              // crypto.setIntegrityProtectionMode(SimpleCrypt::ProtectionHash);
                              QBuffer txB;
                              QDataStream s(&txB);
                              s << txStr;

                              QByteArray cypherBytes = crypto.encryptToByteArray(txB.data());
                              if (crypto.lastError() == SimpleCrypt::ErrorNoError) {
                              qDebug() << cypherBytes;
                              }

                              SimpleCrypt cryptu(Q_UINT64_C(0x7F29B208)); //some random number
                              QByteArray plainBytes = cryptu.decryptToByteArray(cypherBytes);
                              if (!cryptu.lastError() == SimpleCrypt::ErrorNoError) {
                              qDebug() << "decrypt error";
                              return 0;
                              }
                              qDebug() << plainBytes;

                              QString rxStr;
                              QBuffer rxB(&plainBytes);
                              QDataStream rs(&rxB);
                              rs >> rxStr;
                              qDebug() << rxStr;
                              return 0;
                              }
                              @

                              My Output (console):

                              "??Sß+"
                              ""
                              ""

                              What have I missed or using incorrectly?

                              Thanks again for the contribution.

                              1 Reply Last reply
                              0
                              • P Offline
                                P Offline
                                paucoma
                                wrote on last edited by
                                #17

                                So I've played a bit around I've come to the conclusion that I'm using QDataStream incorrectly.

                                My Test Code: main.cpp
                                @
                                #include <QString>
                                #include <QDebug>
                                #include <QBuffer>
                                #include <QDataStream>
                                int main(){
                                QString txStr = "Hello world!";
                                QString rxStr;

                                QBuffer txB;
                                txB.open(QIODevice::ReadWrite);
                                QDataStream s(&txB);
                                qDebug() << txB.size();
                                s << txStr;
                                qDebug() << txB.size();
                                s >> rxStr;
                                qDebug() << rxStr;
                                return 0;
                                }
                                @

                                My Output:
                                0
                                28
                                ""

                                So the buffer is being filled but not correctly being read out.. why not?

                                1 Reply Last reply
                                0
                                • G Offline
                                  G Offline
                                  giesbert
                                  wrote on last edited by
                                  #18

                                  That's an easy question. Your problem is the stream position:

                                  you write to the stream, then start reading after the written bytes :-)

                                  try out the following:

                                  @
                                  #include <QString>
                                  #include <QDebug>
                                  #include <QBuffer>
                                  #include <QDataStream>
                                  int main()
                                  {
                                  QString txStr = "Hello world!";
                                  QString rxStr;

                                  QBuffer txB;
                                  txB.open(QIODevice::WriteOnly);
                                  QDataStream s(&txB);
                                  qDebug() << txB.size();
                                  s << txStr;
                                  qDebug() << txB.size();
                                  txB.close(); // sets stream position to 0 !!!
                                  
                                  txB.open(QIODevice::ReadOnly);
                                  QDataStream s2(&txB);
                                  s2 >> rxStr;
                                  qDebug() << rxStr;
                                  return 0;
                                  

                                  }
                                  @

                                  or use a seek in between

                                  @
                                  #include <QString>
                                  #include <QDebug>
                                  #include <QBuffer>
                                  #include <QDataStream>
                                  int main()
                                  {
                                  QString txStr = "Hello world!";
                                  QString rxStr;

                                  QBuffer txB;
                                  txB.open(QIODevice::WriteOnly);
                                  QDataStream s(&txB);
                                  qDebug() << txB.size();
                                  s << txStr;
                                  qDebug() << txB.size();
                                  txB.seek(0); // sets stream position to 0 !!!
                                  s >> rxStr;
                                  qDebug() << rxStr;
                                  return 0;
                                  

                                  }
                                  @

                                  I did not compile the code, so it might contain typos

                                  Nokia Certified Qt Specialist.
                                  Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                                  1 Reply Last reply
                                  0
                                  • P Offline
                                    P Offline
                                    paucoma
                                    wrote on last edited by
                                    #19

                                    Aha, got it all sorted out, thanks

                                    I had my suspicions on that, but thought that the "<<" and ">>" operators may use seperate index variables.

                                    Andre: it would be great if you could incorporate in the Example usage code the following so it works out of the box.

                                    @
                                    buffer.open(QIODevice::WriteOnly);
                                    buffer.close();
                                    buffer.open(QIODevice::ReadOnly);
                                    @

                                    Because newbies like myself:

                                    • copy + paste + compile
                                      ** if it works -> adapt to needs
                                      ** if it doesn't -> get lost in the simplest things

                                    Although I must admit that I am learning loads of things through all these problems I get myself into.

                                    Gerolf: Once again thanks for your quick and effective response.

                                    1 Reply Last reply
                                    0
                                    • A Offline
                                      A Offline
                                      andre
                                      wrote on last edited by
                                      #20

                                      paucoma, thank you for your comments and suggestions. I have changed the wiki page accordingly. I am glad you solved the problem, and that it turned out the class itself was not at fault ;-)

                                      I must admit that I wrote the examples directly in the wiki page, and thats when errors like these happen. Sorry about that! I hope the current version is more managable? Note that I was talking about "at the other end", implying that the decryption code was not meant to be used in the same function (and thus, implicitly, with the same buffer).

                                      1 Reply Last reply
                                      0
                                      • P Offline
                                        P Offline
                                        paucoma
                                        wrote on last edited by
                                        #21

                                        Thanks Andre for making the modifications.

                                        I have corrected myself a few other details I found.

                                        P.S. I didn't know that I had such a priviledge.

                                        1 Reply Last reply
                                        0
                                        • A Offline
                                          A Offline
                                          andre
                                          wrote on last edited by
                                          #22

                                          Thanks for your effort, I really appreciate it. If you want, you're welcome to update it yourself in the wiki article :-)

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved