Discussion Board

Results 1 to 11 of 11

Thread: AES encryption

  1. #1
    Registered User microsoft2's Avatar
    Join Date
    Jan 2006
    Posts
    279
    Hello,
    How can I encrypt/decrypt data using AES ?

    I couldn't find anything in the wiki.

  2. #2

  3. #3
    Registered User kusumk's Avatar
    Join Date
    Sep 2011
    Posts
    449
    Hi,

    Here is one example of AES buffer encryption of files

    Also, there is this thread which has discussion on similar topic

  4. #4
    Registered User microsoft2's Avatar
    Join Date
    Jan 2006
    Posts
    279
    Thank you for your answers!
    I am new to QT and I guess I prefer to use the Symbian native code, but I am not sure how to set the Initiliazing Vector.
    Can you give me a hint on this?

    Thanks again!

  5. #5

  6. #6
    Registered User kusumk's Avatar
    Join Date
    Sep 2011
    Posts
    449
    Hi,

    Did you already check the links shared before (the symbian ones). The code in the wiki reads from file and encrypts.

  7. #7
    Registered User microsoft2's Avatar
    Join Date
    Jan 2006
    Posts
    279
    Quote Originally Posted by kusumk View Post
    Hi,

    Did you already check the links shared before (the symbian ones). The code in the wiki reads from file and encrypts.
    Yes, but the example has only KAESKey, it does not have IV set.
    I have to set the key and the IV for the AES encoding

  8. #8
    Registered User kusumk's Avatar
    Join Date
    Sep 2011
    Posts
    449
    Hi,

    Did you see this
    It would give you an idea of how it has to be defined, for processing you need to go by the algorithm/available implementations.

  9. #9
    Registered User microsoft2's Avatar
    Join Date
    Jan 2006
    Posts
    279
    What I did is use openssl library that were in the symbian qt sdk (I am new to QT and please correct me if I am using some of the built-in object in a wrong way)
    But now I am not able to compile on QT simulator, any ideas?
    Code:
    #ifdef Q_OS_SYMBIAN
    #include <stdapis/openssl/aes.h>
    #include <stdapis/openssl/evp.h>
    #endif
    
    #ifdef MEEGO_EDITION_HARMATTAN
    #include <openssl/aes.h>
    #include <openssl/evp.h>
    #endif
    
    
    QByteArray aes_encrypt( const QByteArray aTextToEncode )
    {
        EVP_CIPHER_CTX cipherContext;
        EVP_CIPHER_CTX_init( &cipherContext );
    
        const unsigned char* key = (const unsigned char*) "enter 32 bytes key";
        const unsigned char* iv =  (const unsigned char*) "enter 16 bytes vector";
    
        EVP_EncryptInit_ex( &cipherContext, EVP_aes_256_cbc(), NULL, key, iv);
    
        QByteArray encodedText;
        encodedText.resize( aTextToEncode.length() + AES_BLOCK_SIZE + 100 );
    
        int c_len = 0;
        EVP_EncryptUpdate( &cipherContext, ( unsigned char* ) encodedText.data(), &c_len, ( unsigned char* ) aTextToEncode.constData(), aTextToEncode.length() );
    
        qDebug("Encoded length: %d", c_len );
        /* update encodedText with the final remaining bytes */
        int f_len = 0;
        EVP_CipherFinal_ex( &cipherContext, ( unsigned char* ) encodedText.data() + c_len, &f_len );
        qDebug("Encoded final length: %d", f_len );
    
        EVP_CIPHER_CTX_cleanup( &cipherContext );
        encodedText.resize( c_len + f_len );
        return encodedText;
    }
    
    QString aesEncodeAndBase64( QString aTextToEncode )
    {
        QByteArray encodedText = aes_encrypt( aTextToEncode.toAscii() );
        QString res = encodedText.toBase64();
        qDebug("Encoded string %s", qPrintable( res ) );
        return res;
    }
    Last edited by microsoft2; 2012-04-19 at 16:14.

  10. #10
    Registered User kusumk's Avatar
    Join Date
    Sep 2011
    Posts
    449
    Hi,

    Did you include the library details in the symbian section of your .pro file?

    Please check this section for more clarity on how to use symbian libs with QT.

  11. #11
    Registered User microsoft2's Avatar
    Join Date
    Jan 2006
    Posts
    279
    Yes, working ok on symbian and harmattan device
    In my .pro file I specified
    Code:
    symbian: LIBS += -llibcrypto
    contains(MEEGO_EDITION,harmattan): LIBS += -lcrypto
    The only problem is that the emulator does not have evp.h and I have to develop on device

Similar Threads

  1. AES 256 encryption
    By bejoy_ak in forum Mobile Java General
    Replies: 1
    Last Post: 2010-07-20, 18:07
  2. SMS Encryption
    By jayakrishnan.salim in forum Mobile Java General
    Replies: 16
    Last Post: 2009-07-13, 06:26
  3. A5/3 Encryption
    By daverunt in forum General Development Questions
    Replies: 1
    Last Post: 2009-01-16, 11:12
  4. Help with .png encryption
    By mugiwara in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2008-10-27, 08:12
  5. Encryption
    By kolkattakid in forum Symbian C++
    Replies: 0
    Last Post: 2004-05-31, 18:32

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved