QString ClientThread::signRSA(QString st){ unsigned char *sigret=new unsigned char[2048]; unsigned int siglen=0; qDebug(st.toAscii().data()); qDebug(QVariant(strlen(st.toAscii().data())).toString().toAscii()); int i=RSA_sign_ASN1_OCTET_STRING(0, (unsigned char*)st.toAscii().data(), strlen(st.toAscii().data()), sigret, &siglen, rsa_private); if(i==1) { QString a=QByteArray((char*)sigret, siglen).toBase64(); delete sigret; return a; } else { delete sigret; qDebug("sign failed!"); qDebug(QVariant(i).toString().toAscii()); qDebug(ERR_error_string(i, NULL)); return ""; }}
<auth login="Magvaj" pass="wmmTMJIyBg15XcOsIFb59zA3ZO8=" />
<sysuser action="add" name="kot" login="kot" pass="NA4k9qXcsfBYRa2sCqo1A5t+3Qc=" key="LS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tCk1JSUJDZ0tDQVFFQTFpanY4RktFTTN2MklCaW4vL1JQQW9rb1R2cDlwbElKdHVuRVBKZ2dHV092aFdRc2Q3NzcKK2hkOVlWaU0xWVV2Lzg1TmRnNkhibXk4YXFSSEcrT2NvT2R4RmREbnFma0FrNENOUE42SmJnQnNmbFN0MXZGZQorWWpjL2FrNnY3akQvOEwwN2dld0JUTnNYU2JUQjBodUFsNGp0aWVFMTNzN3JwazlnNFQ2bTJCT2p0b0haR2swCm5wMlFKOVBhUHh3SXlIbENJcXBFZ2xINi9wQll4TjVDcFVpSUpGMy9xT2VFanNRSGdpb1RWVE9qWjAxQWYwQUQKM0cvRHRIbXNTODRCTG5aaXNlak5URkpsd3lTNUFDMHR3cW1WVmpOU1Uvcm56Ui8zUmo3Uyt3TS9RNG93clZ3bQpFL3N2SmMrQmJidGk0am1IY0xQeG5jbVhLRmhURTh2SWZ3SURBUUFCCi0tLS0tRU5EIFJTQSBQVUJMSUMgS0VZLS0tLS0KOExhd46mv9n0EC1LaoqbrcDU6f8WLkdhfJi10/ISIzVIXHGHnrbP6QQgPVt6mqu90OT5AQ==" />
bool ClientThread::setPublicKey(QString key){ SSL_load_error_strings(); ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); BIO *mem = BIO_new(BIO_s_mem()); BIO_puts (mem, key.toAscii().data()); qDebug(key.toAscii()); rsa_public=PEM_read_bio_RSAPublicKey(mem, NULL, NULL, NULL); if (rsa_public == NULL) return false; return true;}bool ClientThread::unsignRSA(QString text, QString sign){ QByteArray a=QByteArray::fromBase64(sign.toAscii()); unsigned char digest[2048]; unsigned int dlen; const EVP_MD *evp_md; EVP_MD_CTX md; if ((evp_md = EVP_get_digestbynid(NID_md5)) == NULL) return false; EVP_DigestInit(&md, evp_md); EVP_DigestUpdate(&md, (unsigned char*)text.toAscii().data(), strlen(text.toAscii().data())); EVP_DigestFinal(&md, digest, &dlen); return RSA_verify(NID_md5, digest, dlen, (unsigned char*)a.data(), a.length(), rsa_public);}
QString ClientThread::signRSA(QString st){ unsigned char *sigret=new unsigned char[2048]; unsigned int siglen=0; unsigned char digest[2048]; unsigned int dlen; const EVP_MD *evp_md; EVP_MD_CTX md; if ((evp_md = EVP_get_digestbynid(NID_md5)) == NULL) return false; EVP_DigestInit(&md, evp_md); EVP_DigestUpdate(&md, (unsigned char*)st.toAscii().data(), strlen(st.toAscii().data())); EVP_DigestFinal(&md, digest, &dlen); if(RSA_sign(NID_md5, digest, dlen, sigret, &siglen, rsa_private)) { QString a=QByteArray((char*)sigret, siglen).toBase64(); delete sigret; return a; } else { delete sigret; //qDebug("sign failed!"); return ""; }}bool ClientThread::setPrivateKey(QString filepath, QString pempass){ SSL_load_error_strings(); ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); FILE *priv_key_file=NULL; priv_key_file=fopen(filepath.toAscii(), "rb"); if(priv_key_file) { rsa_private=PEM_read_RSAPrivateKey(priv_key_file, NULL, 0, pempass.toAscii().data()); if (rsa_private == NULL) return false; fclose(priv_key_file); return true; } else return false;}