Showing posts with label BB10. Show all posts
Showing posts with label BB10. Show all posts

Wednesday, October 30, 2013

Qt conversion from date to qstring and from qstring to date


Qt provides very nice library to handle Date and Time. We can use them and convert from Date and Time to Qstring and vice-versa. Below is the sample code snippets providing for both conversion from date to string and string to date in Qt.

Conversion from QDateTime to QString: Below is the sample code for converting datetime to string in Qt. Qt has many string formats to retrieve day, month, year in different formats. for more info check here.

QString dateToString(QDateTime d)
{
 //these three statements just for info.
 QString day = d.toString("dd");
 QString month = d.toString("MM");
 QString year = d.toString("yyyy");
 return d.toString("dd")+"/"+d.toString("MM")+"/"+d.toString("yyyy");
}


Conversion from QString to QDateTime: Below is the sample code to convert from string to date and if the date format string is "dd/mm/yyyy". if the format is different, you need to add corresponding order to get the proper date as the code first converts the string to list using convertQDatetoList and from list to date as below.

QVariantList convertQDatetoList(QString dateTime)
{
 QStringList tempList = dateTime.split("/");
 QVariantList dateList;
 QListIterator i(tempList);
 while(i.hasNext()) {
 dateList.append(i.next());
 }
 return dateList;
}
QDateTime setDateFromString(QString dateString)
{
 QDateTime dt;
 QVariantList dateAsList = convertQDatetoList(dateString);
 if(dateAsList.size()==3) {
 QDate t(dateAsList.at(2).toInt(),
 dateAsList.at(1).toInt(),
 dateAsList.at(0).toInt());
 dt.setDate(t);
 }
 else {
 //date format is not valid,so setting the current date
 dt = QDateTime::currentDateTime();
 }
 return dt;
}


Wednesday, July 24, 2013

BB10 Triple DES Crypto Sample App!!

In this post I am providing sample BB10 App for the crypto algorithm Triple DES. Here I have already provided the AES crypto algorithm for the BB10.

Limitations: as it is sample Application

  • It can encrypt maximum upto 40 char len string
  • if you want more than 40 len, just change the code in encrypt method
  • input should be multiples of SB_DES_BLOCK_SIZE (8)
  • if input is not multiple of 8, you will get undefined values
download the sample app from here.

Please comment below if you need any info or any bug you found.



Thursday, June 20, 2013

BB10 cryptography sample application(AES)

Here is the sample working application for BB10. I have used BlackBerry specific API's to encrypt and decrypt. I have implemented AES and Triple DES algorithms.

Implementing Cryptographic algorithms using API's is easy as we need to use api's directly. But tricky part is conversion of QString to unsigned char*. I struggled a lot and googled , but I could not get the solution. Recently I have seen one sample for encrypting password using md5. In that example, I found the conversion of Qstring to unsigned char * and vice-verse.

Download

So providing here complete working example which may help others.

For Triple Des crypto sample BB10 algorithm refer this link.

Subscribe to: Posts (Atom)

Popular Posts

AltStyle によって変換されたページ (->オリジナル) /