-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsm2key.cpp
59 lines (46 loc) · 1.1 KB
/
sm2key.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "sm2key.h"
#include "sm2.h"
#include "ui_sm2key.h"
Sm2Key::Sm2Key(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Sm2Key)
{
ui->setupUi(this);
}
Sm2Key::~Sm2Key()
{
delete ui;
}
void Sm2Key::on_pushButtonGen_clicked()
{
EVP_PKEY *pkey = NULL;
std::string pem, hex;
pkey = EVP_PKEY_Q_keygen(NULL, NULL, "SM2");
if (pkey == NULL) {
printTSError();
goto end;
}
if (!sm2_key_get_priv_pem(pkey, pem)) {
printTSError();
goto end;
}
this->ui->textBrowserPrivPem->setText(QString::fromStdString(pem));
if (!sm2_key_get_pub_pem(pkey, pem)) {
printTSError();
goto end;
}
this->ui->textBrowserPubPem->setText(QString::fromStdString(pem));
if (!sm2_key_get_pub_hex(pkey, hex)) {
printTSError();
goto end;
}
this->ui->textBrowserPubkey->setText(QString::fromStdString(hex));
if (!sm2_key_get_priv_hex(pkey, hex)) {
printTSError();
goto end;
}
this->ui->textBrowserPrivkey->setText(QString::fromStdString(hex));
end:
EVP_PKEY_free(pkey);
return;
}