Results 1 to 2 of 2

Thread: QCA::RSAPublicKey generating random cryptograms

  1. #1
    Join Date
    Jul 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QCA::RSAPublicKey generating random cryptograms

    Hi! I am on my way to implement RSA encryption in my app. Here is function:

    Qt Code:
    1. void QTlenCryptedSocket::setCryptInfo(QString e, QString pq, QString iv)
    2. {
    3. QCA::BigInteger ipq = QCA::BigInteger();
    4. ipq.fromArray(QCA::SecureArray(QCA::hexToArray(pq.toAscii())));
    5. QCA::BigInteger ie(e);
    6. QCA::RSAPublicKey pubkey = QCA::RSAPublicKey(ipq, ie);
    7. qDebug(QCA::arrayToHex(pubkey.n().toArray().toByteArray()).toAscii());
    8. //serverIV = QCA::InitializationVector(QCA::hexToArray(iv));
    9. //wektor i kluczyk
    10. //clientIV = QCA::InitializationVector(16);
    11. //aesKey = QCA::SymmetricKey(16);
    12. QCA::SymmetricKey aesKey(QCA::hexToArray("c73b79e172d22ba4d8d0dec8f80b9c7c")); // = QCA::SymmetricKey(QCA::hexToArray("c73b79e172d22ba4d8d0dec8f80b9c7c"));
    13. QByteArray key = aesKey.toByteArray();
    14. //żeby kluczyk pasował
    15. while (key.length() != 64)
    16. key.append(QCA::hexToArray("00"));
    17. QCA::SecureArray SAKey(key);
    18. //dotąd działa, tu coś pieprzy
    19. QCA::SecureArray result = pubkey.encrypt(SAKey, QCA::EME_PKCS1_OAEP);
    20. qDebug("------------------------------------------------------------");
    21. qDebug("Expected value for RSA e");
    22. qDebug(e.toAscii());
    23. qDebug("Value for RSA e passed to pubkey object");
    24. qDebug(ie.toString().toAscii());
    25. qDebug("Value for RSA e stored in pubkey object");
    26. qDebug(pubkey.e().toString().toAscii());
    27. qDebug("------------------------------------------------------------");
    28. qDebug("Expected value for RSA pq");
    29. qDebug(pq.toAscii());
    30. qDebug("Value for RSA e passed to pubkey object");
    31. qDebug(QCA::arrayToHex(ipq.toArray().toByteArray()).toAscii());
    32. qDebug("Value for RSA e stored in pubkey object");
    33. qDebug(QCA::arrayToHex(pubkey.n().toArray().toByteArray()).toAscii());
    34. qDebug("------------------------------------------------------------");
    35. qDebug("Expected value for raw string (without leading zeroes)");
    36. qDebug("c73b79e172d22ba4d8d0dec8f80b9c7c");
    37. qDebug("Raw string (with leading zeroes)");
    38. qDebug(QCA::arrayToHex(SAKey.toByteArray()).toAscii());
    39. qDebug("------------------------------------------------------------");
    40. qDebug("Expected value for encrypted string");
    41. qDebug("12fcb5bf57d24b0ed9f2a04aaf4e381b1b8d04de5096cf41ba9c097a3d17ed7aaaa52383f189296844257e98629049c1f84a2493f2fbb5d3889e27a59f0f95b");
    42. qDebug("Encrypted string");
    43. qDebug(QCA::arrayToHex(result.toByteArray()).toAscii());
    44. qDebug("------------------------------------------------------------");
    45. result = pubkey.encrypt(SAKey, QCA::EME_PKCS1_OAEP);
    46. qDebug("Encrypted string");
    47. qDebug(QCA::arrayToHex(result.toByteArray()).toAscii());
    48. qDebug("------------------------------------------------------------");
    49. QByteArray hash = QCA::arrayToHex(result.toByteArray()).toAscii();
    50. QByteArray ivHash = QCA::arrayToHex(clientIV.toByteArray()).toAscii();
    51. outCipher = new QCA::Cipher(QString("aes128"),QCA::Cipher::CBC,
    52. // use no padding, as we need to use our own version
    53. QCA::Cipher::NoPadding,
    54. // this object will encrypt
    55. QCA::Encode,
    56. aesKey, clientIV);
    57. inCipher = new QCA::Cipher(QString("aes128"),QCA::Cipher::CBC,
    58. // use no padding, as we need to use our own version
    59. QCA::Cipher::NoPadding,
    60. // this object will decrypt
    61. QCA::Decode,
    62. aesKey, QCA::InitializationVector(QCA::hexToArray(iv)));
    63. socket->write("<cipher k1='" + hash + "' k2='" + ivHash + "' />");
    64. }
    To copy to clipboard, switch view to plain text mode 

    there is some info dumped with debug inlines

    ------------------------------------------------------------
    Expected value for RSA e
    10001
    Value for RSA e passed to pubkey object
    10001
    Value for RSA e stored in pubkey object
    10001
    ------------------------------------------------------------
    Expected value for RSA pq
    1554a7873b24bb3e0c0101675e018fe184fa3c9e66e80a4c33 b6f2552e7e9c2b671865e1b56ce1701804c550cf124a8614b2 5e1f66c1c58a629f7be94b3650fd
    Value for RSA e passed to pubkey object
    1554a7873b24bb3e0c0101675e018fe184fa3c9e66e80a4c33 b6f2552e7e9c2b671865e1b56ce1701804c550cf124a8614b2 5e1f66c1c58a629f7be94b3650fd
    Value for RSA e stored in pubkey object
    1554a7873b24bb3e0c0101675e018fe184fa3c9e66e80a4c33 b6f2552e7e9c2b671865e1b56ce1701804c550cf124a8614b2 5e1f66c1c58a629f7be94b3650fd
    ------------------------------------------------------------
    Expected value for raw string (without leading zeroes)
    c73b79e172d22ba4d8d0dec8f80b9c7c
    Raw string (with leading zeroes)
    c73b79e172d22ba4d8d0dec8f80b9c7c000000000000000000 00000000000000000000000000000000000000000000000000 0000000000000000000000000000
    ------------------------------------------------------------
    Expected value for encrypted string
    12fcb5bf57d24b0ed9f2a04aaf4e381b1b8d04de5096cf41ba 9c097a3d17ed7aaaa52383f189296844257e98629049c1f84a 2493f2fbb5d3889e27a59f0f95b
    Encrypted string
    0b569fa16b74ce23a47a7b9b887c4c5e269106801eb999c13d 0a88df9bb83bd7494ca574ef351f90afc5346ea9f9853bf13e 7adf0d9da0d979f8ff54addb74d1
    ------------------------------------------------------------
    Encrypted string
    0cdfbfad1876a59c0eaa3e217181f61f31f7afb798f7721bff 4d93c4f43ae555ee22658ed8da3e3a1cef46ebccfbc2fd3666 37a0b685fe63de7a18c5071ee7ec
    ------------------------------------------------------------


    how to get proper and not changing values?

  2. #2
    Join Date
    Jul 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QCA::RSAPublicKey generating random cryptograms

    sorry for double post - its QCA "fault" - it cannot provide no-padding RSA encoding right now. I asked on devel mailing list to introduce that, for now I am using OpenSSL and it works somehow. Can be closed.

Similar Threads

  1. Generating random characters
    By munna in forum General Discussion
    Replies: 1
    Last Post: 25th November 2006, 13:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.