[Qt-interest] XOR Encryption Problems.

Raja Rokkam rokkamraja at gmail.com
Mon Feb 8 15:50:18 CET 2010


Hi All,

        Below is my encryption function and setter/getter for a UI which
needs to store login information. Can someone please tell me whether it is
robust ? I am seeing issues with the role being stored in file. Sometimes,
it is getting stored and sometimes it is not getting stored. I am getting
the values correctly. Please let me know where I am going wrong?
----------------------------------------------------------------------

string XOR(string value,string key)
{
    string retval(value);

    short unsigned int klen=key.length();
    short unsigned int vlen=value.length();
    short unsigned int k=0;
    short unsigned int v=0;

    for(v = 0;v<vlen;v++)
    {
        retval[v]=value[v]^key[k];
        k=(++k<klen?k:0);
    }

    return retval;
}

void StorageEngine::authenStore( const QString &userName, const QString
&password, const QString &token, const QString &groupName, const QString
&role )
{
    ofstream fp;
    fp.open( userDetails );
    string strUserName = userName.toStdString();
    string strGroupName = groupName.toStdString();
    string strPassword = password.toStdString();
    string val = XOR( strPassword, strUserName );
    string tokenStr = XOR(token.toStdString(),strUserName);
    string userRole = role.toStdString();

    fp << userName.toStdString() << endl;
    fp << groupName.toStdString() << endl;
    fp << strPassword << endl;
    fp << token.toStdString() << endl;
    fp << userRole << endl;

    fp.close();
}

QString &StorageEngine::getAuthenStore( QString &userName, QString
&password, QString &token, QString &groupName, QString &role )
{
    ifstream fp;
    string usernameline, groupLine;
    string passwdline;
    string tokenline;
    string roleUser;
    fp.open( userDetails );
    getline(fp,usernameline);
    getline( fp, groupLine );
    getline( fp, passwdline);
    getline( fp,tokenline);
    getline( fp, roleUser );
    string passwd = XOR( passwdline, usernameline );
    string authtoken = XOR(tokenline,usernameline);
    userName = usernameline.c_str();
    groupName = groupLine.c_str();
    password = passwd.c_str();
    token = authtoken.c_str();
    role = roleUser.c_str();
    return password;
}


Thanks,
Raja.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100208/60b2860e/attachment.html 


More information about the Qt-interest-old mailing list