I need help from some one to convert the following line of code from ruby to qt c++:
KEY = %w(30 81 9F 30 0D 06 09 2A 86 48 86 F7 0D 01 01 01 05 00 03 81 8D 00).map{|s| s.hex}.pack(‘C*’)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Quick explanation:
creates temporary QByteArray with your key as string
removes all spaces in temporary QByteArray, so it contains only characters 0..F
converts hex-encoded QByteArray into QByteArray containing unsigned 8-bit integers (i.e. C++ char type). It means that it takes every pair of hex digits from original QByteArray ( for example “41”) and converts it to integer (“41” will be converted to 65 = 4*16 + 1) and appends this value into new QByteArray.
If you need key as a “const char *” you can use QByteArray::constData() method, but you have to remember that the pointer returned by this method is valid only as long as original QByteArray is valid (quote from documentation: “as long as the byte array isn’t reallocated or destroyed”). So if you need to store the key data, keep it as QByteArray or make a copy of const char * returned by constData().