openssl qt 生成秘钥_关于openssl作的rsa生成密钥及加解密(2)

当前位置:我的异常网» QT开发 » 关于openssl作的rsa生成密钥及加解密

关于openssl作的rsa生成密钥及加解密(2)

www.myexceptions.net  网友分享于:2013-07-05  浏览:245次

out <

for(int i=0; i

{

quint8 tmmm=cipher[i];

out <

// qDebug()<

}

out.setVersion(QDataStream::Qt_4_6);

qDebug("cRsa::%s",cipher);

}

QString decryptRsa()

{

RSA *rsaK=RSA_new();

OpenSSL_add_all_algorithms();

BIO *BP;

#ifdef Q_WS_WIN

QString path=WIN_TtempPath+"/private.pem";

QByteArray ba = path.toLatin1();

const char *c_str2 = ba.data();

printf("str2: %s", c_str2);

BP=BIO_new_file(c_str2, "rb");

#endif

#ifdef Q_WS_X11

const char *path = (xmlPath + "/private.pem").toLocal8Bit().data();

qDebug("private:%s", path);

BP=BIO_new_file(path, "rb");

#endif

char PSW[]="abc";

rsaK=PEM_read_bio_RSAPrivateKey(BP,&rsaK,0,PSW);

qDebug()<

flen=RSA_size(rsaK);

if(rsaK==NULL)

{

qDebug("read failed!\n");

BIO_free(BP);

RSA_free(rsaK);

exit(-1);

}

qDebug("get key successfully\n");

#ifdef Q_WS_WIN

QFile file1(WIN_TtempPath + "/file.dat");

#else

QFile file1(xmlPath + "/file.dat");

#endif

if(file1.open(QIODevice::ReadOnly))

qDebug()<

QDataStream in(&file1);    // read the data serialized from the file

in.setVersion(QDataStream::Qt_4_6);

quint32 magic;

in >> magic;

qDebug()<

unsigned char tmpp[flen];

unsigned char cipher[flen];

for(int j=0;j

{

quint8 tm;

in>>tm;           // extract "the answer is" and 42

tmpp[j]=tm;

//qDebug()<

//qDebug()<

}

qDebug("dRsa::%s",tmpp);

flen = RSA_private_decrypt( flen, tmpp, cipher, rsaK , RSA_NO_PADDING );

文章评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值