Пример #1
0
 void crypter_make_key_iv(void)
 {
   SecureByteArray masterPassword = QString("7h15p455w0rd15m0r37h4n53cr37").toUtf8();
   QByteArray salt = QString("this is my salt.").toUtf8();
   SecureByteArray key;
   SecureByteArray IV;
   Crypter::makeKeyAndIVFromPassword(masterPassword, salt, key, IV);
   QVERIFY(key.length() == Crypter::AESKeySize);
   QVERIFY(key.toBase64() == "vGoCE/dCUIpQFfPEHnh+qY9HLTeMNPFPMlA9dz5snjs=");
   QVERIFY(IV.length() == Crypter::AESBlockSize);
   QVERIFY(IV.toBase64() == "mHg3BMpk9vwK+eY1YJWAKg==");
 }
Пример #2
0
  void crypter_encode_decode(void)
  {
    SecureByteArray masterPassword = QString("7h15p455w0rd15m0r37h4n53cr37").toUtf8();
    QByteArray salt = Crypter::randomBytes(Crypter::SaltSize);
    SecureByteArray key;
    SecureByteArray IV;
    Crypter::makeKeyAndIVFromPassword(masterPassword, salt, key, IV);
    QVERIFY(key.length() == Crypter::AESKeySize);
    QVERIFY(IV.length() == Crypter::AESBlockSize);

    SecureByteArray KGK = Crypter::randomBytes(Crypter::KGKSize);
    QByteArray data = Crypter::randomBytes(1024);
    QByteArray cipher = Crypter::encode(key, IV, salt, KGK, data, true);

    SecureByteArray KGK2;
    QByteArray plain = Crypter::decode(masterPassword, cipher, true, KGK2);
    QVERIFY(plain == data);
    QVERIFY(KGK == KGK2);
  }