Generate QByteArray format with Golang - qt

I have an application on QT which reads from a file with text in a QByteArray format (the information belongs to a certificate stored in a file). Looks like this:
certificate="#ByteArray(0\x82\tF\x2\x1\x3\x30\x82\t\x10\x6\t*\x86H\x86\xf7\r\x1\a\x1\xa0\x82\t\x1\x4\x82\b\xfd\x30\x82\b\xf9\x30\x82\x3\xad\x6\t*\x86H\x86\xf7\r\x1\a\x1\xa0\x82\x3\x9e\x4\x82\x3\x9a\x30\x82\x3\x96\x30\x82\x3\x92\x6\v*\x86H\x86\xf7\r\x1\f\n\x1\x3\xa0\x82\x3+0\x82\x3'\x6\n*\x86H\x86\xf7\r\x1\t\x16\x1\xa0\x82\x3\x17\x4\x82\x3\x13\x30\x82\x3\xf\x30\x82\x1\xf7\xa0\x3\x2\x1\x2\x2\x1\x1\x30\r\x6\t*\x86H\x86\xf7\r\x1\x1\x5\x5\0\x30\x16\x31\x14\x30\x12\x6\x3U\x4\x3\f\vMumble User0\x1e\x17\r200130204841Z\x17\r400125204841Z0\x16\x31\x14\x30\x12\x6\x3U\x4\x3\f\vMumble User0\x82\x1\"0\r\x6\t*\x86H\x86\xf7\r\x1\x1\x1\x5\0\x3\x82\x1\xf\0\x30\x82\x1\n\x2\x82\x1\x1\0\xc6\x1d\x66\x8f\xc2\x31-N\xa1\xa0,\xf4\xb9\xc6\x80\x30)\xba\xf6\x17\x37\xec\x82\x1a\xf2s\xfc\xbc\x86\x93\x97\x83G\xccU(\vnr\t\xa8\x61\x12\b\x8f\xd6\x95T?\xc9\xe8\xe3v\x80%\xe3}\xe6,\x90\a\xe2\x18\xe0V\x80k\xee\x88&H <2G\x81\xec\xd6\xf1\xe9\xd0\xcat\x13\x9c?\x81\xcf\xaf\x14J\xc1X\xa5k\x9f\xf6P\xd9y\b\xa2\xe7\xaf\xa0l\xa0\xb4\xc7g\xc3*\xdd\x10\x16\xde\xe\xc3
Now I need generate the same format (QByteArray) using a GO application, but didn't find how generate this format.
Anyone can point me to some example or documentation on how create the same format of a QByteArray using another language (go)?
Thanks in advance.

QByteArray is just an array of bytes, in go that would just be []byte

Related

QR Code URL data not readable or encrypted

There is an app which I use, which can read the name of a location from a qr code.
Recently, the qr code was changed so that the name of the location is no longer readable by zxing or any other barcode reader that I can find. Instead, I get a long string of numbers and letters. (The data that I need comes after the '&ln=' or '&eln=' in the url that is returned.)
The first example below is the new qr code. It returns the following URL:
https://mysejahtera.malaysia.gov.my/qrscan?lId=62419209a90dcd50091c36cb&eln=TW9qaXRvJ3MgQmVlciBCYXI=&formType=REGULAR&isExternal=false
The second one returns this:
https://mysejahtera.malaysia.gov.my/qrscan?lId=5edc745eb9e6850245c07e4b&ln=Osdin_Lighting_Enterprise
The original app can read the long location string in both the encrypted and human readable format. I want to be able to do the same. For example, the location of the first url is "Mojito's Beer Bar." The original app can read this and displays it correctly.
My feeling is that there must be a private key encryption which the app used to decipher the code. However, is it possible that there is a simple reason that a normal barcode/qrcode reader can't get the plain readable location text?
All I am looking for here is some pointers of where I should be looking. I have the decompiled source code from the MySejahtera app and have been digging through it without any luck. I'm happy to share this if anyone would be willing to help.
The "encoded" URL contains the value TW9qaXRvJ3MgQmVlciBCYXI= for the attribute eln. This is obviously a Base64 encoded value.
If you run the value through a Base64 decoder (e.g. https://www.base64decode.org/), the result is:
Mojito's Beer Bar
Base64 doesn't specify what text encoding is used. But likely it is UTF-8.

Converting UTF-16 QByteArray to QString

I have a QByteArray which contains bytes in UTF-16 format.
A Java program sends data to a QT program via socket using
//dos is DataOutPutStream
dos.writeChars("hello world");
On the receiver side in QT program I read the data from socket into QByteArray and I want to convert it to a QString. inspecting the data variable of QByteArray it has 0h0e0l0l0o0 0w0o0r0l0d
When I try to make a QString out of it like this
QString str(byteArray)
The resulting string is empty perhaps because it encounters a 0 byte at the start and ofcouse because the documentation of the constructor I am using says that it internally uses fromAscii and what I am passing is not ascii.
I guess i have to somehow use QString::fromUTF-16 but that requires a ushort* and I have a QbyteArray.
Please advise what is the best way to do it.
Thanks,
Get a pointer to the QByteArray.data() and cast it to ushort*
This would work, assuming your utf-16 data is of the same endianness or has the BOM (Byte Order Mark):
QByteArray utf16 = ....;
auto str = QString::fromUtf16(
reinterpret_cast<const ushort*>(utf16.constData()));

QFile class start of stram

I'm using Qt for reading binary file. I read file with QFile object, but sometimes I need to go back at begining of the file and read file again, but I don't know how to do that.
You can use the seek function on your file :
file.seek(0);
If you are reading the file using a QTextStream you should use the seek function on the stream.

in asp.net how to convert the binary file to a file in a string format and display it in a page

I wish to know how to convert the byte array file to a file in a string format and display it in a webpage. Can anyone tell me how can i perform this?
Unsure of what your actual aim is, a good place to start investigating would be the System.Text.Encoding class
http://msdn.microsoft.com/en-us/library/system.text.encoding.aspx

How to avoid type conversion in flex from string to number?

I am returning 12345678910111213171819 from java to flex, with in xml tags using http serivce. The result format is object.
but when I display the text it automatically converted or treated as number
so it displays like 1.234567891011121317181 x e^21 ....
How to avoid this?
Thanks in advance.
Regards,
Sankara narayanan Ekambaranathan.
Can't you simply coerce it with String()?
var returnedObject:String = String(123463457695);
Well the easiest solution is just a little workaround to the issue:
Instead of sending the open data like
12345678910111213171819
Convert the data into Base 64 Encoding While transmitting
MTIzNDU2Nzg5MTAxMTEyMTMxNzE4MTk=
In Flex Convert back the data using the standard Base 64 Decoder provided with flex
to convert it back into String instead of number format during XML parsing ;)
I faced the same problem on one of my projects.
After a lot of googling and investigation I fixed it by changing result format to XML and manually parsing the XML with explicit type conversions.
Another (actually, more correct) way is to define a schema for the response and somehow apply it to the XML decoder but I haven't found an easy way to do it.

Resources