You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.4 KiB
C++
71 lines
1.4 KiB
C++
#include "eetsigner.h"
|
|
|
|
#include <QDebug>
|
|
#include <QStringList>
|
|
|
|
EetSigner::EetSigner(QObject *parent) : QObject(parent)
|
|
{
|
|
}
|
|
|
|
QByteArray EetSigner::signData(const QByteArray &data)
|
|
{
|
|
if (!QCA::isSupported("sha256"))
|
|
{
|
|
return QByteArray();
|
|
}
|
|
|
|
if (m_result != QCA::ConvertGood || m_bundle.isNull())
|
|
{
|
|
return QByteArray();
|
|
}
|
|
|
|
QCA::PrivateKey privKey = m_bundle.privateKey();
|
|
|
|
return privKey.signMessage(QCA::MemoryRegion(data), QCA::EMSA3_SHA256);
|
|
}
|
|
|
|
QByteArray EetSigner::sha1HashData(const QByteArray &data)
|
|
{
|
|
if (!QCA::isSupported("sha1"))
|
|
{
|
|
return QByteArray();
|
|
}
|
|
|
|
return QCA::Hash("sha1").hash(QCA::MemoryRegion(data)).toByteArray();
|
|
}
|
|
|
|
QByteArray EetSigner::sha256HashData(const QByteArray &data)
|
|
{
|
|
if (!QCA::isSupported("sha256"))
|
|
{
|
|
return QByteArray();
|
|
}
|
|
|
|
return QCA::Hash("sha256").hash(QCA::MemoryRegion(data)).toByteArray();
|
|
}
|
|
|
|
QString EetSigner::getCertificate()
|
|
{
|
|
if (!QCA::isSupported("cert"))
|
|
{
|
|
return "";
|
|
}
|
|
|
|
if (m_result != QCA::ConvertGood || m_bundle.isNull())
|
|
{
|
|
return "";
|
|
}
|
|
|
|
if (!m_bundle.certificateChain().isEmpty())
|
|
{
|
|
return QString(m_bundle.certificateChain().primary().toDER().toBase64());
|
|
}
|
|
|
|
return "";
|
|
}
|
|
|
|
void EetSigner::setup(const QString &certPath, const QCA::SecureArray &certPasswd)
|
|
{
|
|
m_bundle = QCA::KeyBundle::fromFile(certPath, certPasswd, &m_result);
|
|
}
|