{
QCA::BigInteger ipq = QCA::BigInteger();
ipq.fromArray(QCA::SecureArray(QCA::hexToArray(pq.toAscii())));
QCA::BigInteger ie(e);
QCA::RSAPublicKey pubkey = QCA::RSAPublicKey(ipq, ie);
qDebug(QCA::arrayToHex(pubkey.n().toArray().toByteArray()).toAscii());
//serverIV = QCA::InitializationVector(QCA::hexToArray(iv));
//wektor i kluczyk
//clientIV = QCA::InitializationVector(16);
//aesKey = QCA::SymmetricKey(16);
QCA::SymmetricKey aesKey(QCA::hexToArray("c73b79e172d22ba4d8d0dec8f80b9c7c")); // = QCA::SymmetricKey(QCA::hexToArray("c73b79e172d22ba4d8d0dec8f80b9c7c"));
//żeby kluczyk pasował
while (key.length() != 64)
key.append(QCA::hexToArray("00"));
QCA::SecureArray SAKey(key);
//dotąd działa, tu coś pieprzy
QCA::SecureArray result = pubkey.encrypt(SAKey, QCA::EME_PKCS1_OAEP);
qDebug("------------------------------------------------------------");
qDebug("Expected value for RSA e");
qDebug(e.toAscii());
qDebug("Value for RSA e passed to pubkey object");
qDebug(ie.toString().toAscii());
qDebug("Value for RSA e stored in pubkey object");
qDebug(pubkey.e().toString().toAscii());
qDebug("------------------------------------------------------------");
qDebug("Expected value for RSA pq");
qDebug(pq.toAscii());
qDebug("Value for RSA e passed to pubkey object");
qDebug(QCA::arrayToHex(ipq.toArray().toByteArray()).toAscii());
qDebug("Value for RSA e stored in pubkey object");
qDebug(QCA::arrayToHex(pubkey.n().toArray().toByteArray()).toAscii());
qDebug("------------------------------------------------------------");
qDebug("Expected value for raw string (without leading zeroes)");
qDebug("c73b79e172d22ba4d8d0dec8f80b9c7c");
qDebug("Raw string (with leading zeroes)");
qDebug(QCA::arrayToHex(SAKey.toByteArray()).toAscii());
qDebug("------------------------------------------------------------");
qDebug("Expected value for encrypted string");
qDebug("12fcb5bf57d24b0ed9f2a04aaf4e381b1b8d04de5096cf41ba9c097a3d17ed7aaaa52383f189296844257e98629049c1f84a2493f2fbb5d3889e27a59f0f95b");
qDebug("Encrypted string");
qDebug(QCA::arrayToHex(result.toByteArray()).toAscii());
qDebug("------------------------------------------------------------");
result = pubkey.encrypt(SAKey, QCA::EME_PKCS1_OAEP);
qDebug("Encrypted string");
qDebug(QCA::arrayToHex(result.toByteArray()).toAscii());
qDebug("------------------------------------------------------------");
QByteArray hash
= QCA
::arrayToHex(result.
toByteArray()).
toAscii();
QByteArray ivHash
= QCA
::arrayToHex(clientIV.
toByteArray()).
toAscii();
outCipher
= new QCA
::Cipher(QString("aes128"),QCA
::Cipher::CBC,
// use no padding, as we need to use our own version
QCA::Cipher::NoPadding,
// this object will encrypt
QCA::Encode,
aesKey, clientIV);
inCipher
= new QCA
::Cipher(QString("aes128"),QCA
::Cipher::CBC,
// use no padding, as we need to use our own version
QCA::Cipher::NoPadding,
// this object will decrypt
QCA::Decode,
aesKey, QCA::InitializationVector(QCA::hexToArray(iv)));
socket->write("<cipher k1='" + hash + "' k2='" + ivHash + "' />");
}
void QTlenCryptedSocket::setCryptInfo(QString e, QString pq, QString iv)
{
QCA::BigInteger ipq = QCA::BigInteger();
ipq.fromArray(QCA::SecureArray(QCA::hexToArray(pq.toAscii())));
QCA::BigInteger ie(e);
QCA::RSAPublicKey pubkey = QCA::RSAPublicKey(ipq, ie);
qDebug(QCA::arrayToHex(pubkey.n().toArray().toByteArray()).toAscii());
//serverIV = QCA::InitializationVector(QCA::hexToArray(iv));
//wektor i kluczyk
//clientIV = QCA::InitializationVector(16);
//aesKey = QCA::SymmetricKey(16);
QCA::SymmetricKey aesKey(QCA::hexToArray("c73b79e172d22ba4d8d0dec8f80b9c7c")); // = QCA::SymmetricKey(QCA::hexToArray("c73b79e172d22ba4d8d0dec8f80b9c7c"));
QByteArray key = aesKey.toByteArray();
//żeby kluczyk pasował
while (key.length() != 64)
key.append(QCA::hexToArray("00"));
QCA::SecureArray SAKey(key);
//dotąd działa, tu coś pieprzy
QCA::SecureArray result = pubkey.encrypt(SAKey, QCA::EME_PKCS1_OAEP);
qDebug("------------------------------------------------------------");
qDebug("Expected value for RSA e");
qDebug(e.toAscii());
qDebug("Value for RSA e passed to pubkey object");
qDebug(ie.toString().toAscii());
qDebug("Value for RSA e stored in pubkey object");
qDebug(pubkey.e().toString().toAscii());
qDebug("------------------------------------------------------------");
qDebug("Expected value for RSA pq");
qDebug(pq.toAscii());
qDebug("Value for RSA e passed to pubkey object");
qDebug(QCA::arrayToHex(ipq.toArray().toByteArray()).toAscii());
qDebug("Value for RSA e stored in pubkey object");
qDebug(QCA::arrayToHex(pubkey.n().toArray().toByteArray()).toAscii());
qDebug("------------------------------------------------------------");
qDebug("Expected value for raw string (without leading zeroes)");
qDebug("c73b79e172d22ba4d8d0dec8f80b9c7c");
qDebug("Raw string (with leading zeroes)");
qDebug(QCA::arrayToHex(SAKey.toByteArray()).toAscii());
qDebug("------------------------------------------------------------");
qDebug("Expected value for encrypted string");
qDebug("12fcb5bf57d24b0ed9f2a04aaf4e381b1b8d04de5096cf41ba9c097a3d17ed7aaaa52383f189296844257e98629049c1f84a2493f2fbb5d3889e27a59f0f95b");
qDebug("Encrypted string");
qDebug(QCA::arrayToHex(result.toByteArray()).toAscii());
qDebug("------------------------------------------------------------");
result = pubkey.encrypt(SAKey, QCA::EME_PKCS1_OAEP);
qDebug("Encrypted string");
qDebug(QCA::arrayToHex(result.toByteArray()).toAscii());
qDebug("------------------------------------------------------------");
QByteArray hash = QCA::arrayToHex(result.toByteArray()).toAscii();
QByteArray ivHash = QCA::arrayToHex(clientIV.toByteArray()).toAscii();
outCipher = new QCA::Cipher(QString("aes128"),QCA::Cipher::CBC,
// use no padding, as we need to use our own version
QCA::Cipher::NoPadding,
// this object will encrypt
QCA::Encode,
aesKey, clientIV);
inCipher = new QCA::Cipher(QString("aes128"),QCA::Cipher::CBC,
// use no padding, as we need to use our own version
QCA::Cipher::NoPadding,
// this object will decrypt
QCA::Decode,
aesKey, QCA::InitializationVector(QCA::hexToArray(iv)));
socket->write("<cipher k1='" + hash + "' k2='" + ivHash + "' />");
}
To copy to clipboard, switch view to plain text mode
Bookmarks