Is there a way to make output from QCryptographicHash readable QByteArray?
-
@Christian-Ehrlicher my bad but this is inly excerpt. In the program it is a member and is deleted in the destructor.
And it is on the heap since I don't know how to initialise it otherwise (method selection). One of the constrains I face is that it has to be SHA-512 and only that.So you say QByteArray::toBase64 should suffice?
@mrjj I examined and tested the code from which excerpts are here, worked over 100 times both in loop with no wait and waiting for user input.
wrote on 17 Jun 2021, 17:28 last edited byThis post is deleted! -
wrote on 17 Jun 2021, 17:32 last edited by artwaw
IT WORKS!
Thank you!@Christian-Ehrlicher That works, of course. But outside of the example it looks like this:
I wrapped all those hash-generating bits into a small class. For convenience, I have there:private: QRandomGenerator generator; QCryptographicHash *hash;
In the constructor I init the generator and the hash. So I have
hash = new QCryptographicHash(QCryptographicHash::Sha512);
that is later deleted in the destructor. It apparently is a weak day for me but I failed to find a way of this private member NOT to be on the heap.EDIT:
@JonB I saw your comment :)
I understood, just at this hour I am not entirely online, just from time to time :) -
IT WORKS!
Thank you!@Christian-Ehrlicher That works, of course. But outside of the example it looks like this:
I wrapped all those hash-generating bits into a small class. For convenience, I have there:private: QRandomGenerator generator; QCryptographicHash *hash;
In the constructor I init the generator and the hash. So I have
hash = new QCryptographicHash(QCryptographicHash::Sha512);
that is later deleted in the destructor. It apparently is a weak day for me but I failed to find a way of this private member NOT to be on the heap.EDIT:
@JonB I saw your comment :)
I understood, just at this hour I am not entirely online, just from time to time :)wrote on 17 Jun 2021, 17:37 last edited by JonB@artwaw
Personally I don't worry about heap vs stack as some others do, when I did Python it's all heap anyway. And sometimes I heap to avoid include dependencies in header files.But why can't you have
QCryptographicHash hash(QCryptographicHash::Sha512);
as the member variable instead of pointer? -
@artwaw
Personally I don't worry about heap vs stack as some others do, when I did Python it's all heap anyway. And sometimes I heap to avoid include dependencies in header files.But why can't you have
QCryptographicHash hash(QCryptographicHash::Sha512);
as the member variable instead of pointer? -
@JonB When I do:
private: QCryptographicHash hash(QCryptographicHash::Sha512);
I get instant
/Users/(username)/cpp/512hash/cryptoclass/cryptoclass.h:24: error: no type named 'Sha512' in 'QCryptographicHash'
wrote on 17 Jun 2021, 17:49 last edited by JonB@artwaw
Ah! That will be because you are in the "sometimes I heap to avoid include dependencies in header files" I mentioned :)Intentionally or not, in your
.h
file you have preceded this line withclass QCryptographicHash;
That allows
QCryptographicHash *
declarations to the incomplete type.You will need
#include <QCryptographicHash>
to make the declaration acceptable. If that is what you wish to do.
I see for example you alreday have
QRandomGenerator generator;
so you have chosen to do that one with include.
-
@artwaw
Ah! That will be because you are in the "sometimes I heap to avoid include dependencies in header files" I mentioned :)Intentionally or not, in your
.h
file you have preceded this line withclass QCryptographicHash;
That allows
QCryptographicHash *
declarations to the incomplete type.You will need
#include <QCryptographicHash>
to make the declaration acceptable. If that is what you wish to do.
I see for example you alreday have
QRandomGenerator generator;
so you have chosen to do that one with include.
-
@JonB When I do:
private: QCryptographicHash hash(QCryptographicHash::Sha512);
I get instant
/Users/(username)/cpp/512hash/cryptoclass/cryptoclass.h:24: error: no type named 'Sha512' in 'QCryptographicHash'
wrote on 17 Jun 2021, 17:55 last edited by@artwaw said in Is there a way to make output from QCryptographicHash readable QByteArray?:
I get instant
/Users/(username)/cpp/512hash/cryptoclass/cryptoclass.h:24: error: no type named 'Sha512' in 'QCryptographicHash'
Then I have no idea why you get a "no type" error for
QCryptographicHash hash(QCryptographicHash::Sha512);
in a
.h
but not in a.cpp
or whyhash = new QCryptographicHash(QCryptographicHash::Sha512);
is acceptable.
-
@artwaw said in Is there a way to make output from QCryptographicHash readable QByteArray?:
I get instant
/Users/(username)/cpp/512hash/cryptoclass/cryptoclass.h:24: error: no type named 'Sha512' in 'QCryptographicHash'
Then I have no idea why you get a "no type" error for
QCryptographicHash hash(QCryptographicHash::Sha512);
in a
.h
but not in a.cpp
or whyhash = new QCryptographicHash(QCryptographicHash::Sha512);
is acceptable.
wrote on 17 Jun 2021, 17:57 last edited by artwaw@JonB I can live with one pair of new/delete :)
Thank you all who contributed and especially to @Christian-Ehrlicher for pointing me out the obvious.
15/15