Advertisement
Guest User

Untitled

a guest
May 27th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <QCoreApplication>
  2. #include <QDebug>
  3. #include <CSP_WinCrypt.h>
  4. #include <WinCryptEx.h>
  5.  
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9. QCoreApplication a(argc, argv);
  10.  
  11. HCRYPTPROV hProv;
  12. HCRYPTKEY hSessionKey;
  13.  
  14.  
  15. if (!CryptAcquireContext(&hProv, NULL, NULL,
  16. PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
  17. {
  18.  
  19. qDebug()<<"Error1";
  20. //Error("CryptAcquireContext");
  21. //return;
  22. }
  23.  
  24.  
  25. qDebug() << "Cryptographic provider initialized";
  26.  
  27. // Генерация сессионного ключа
  28. if (!CryptGenKey(hProv, CALG_RC4,
  29. CRYPT_ENCRYPT | CRYPT_DECRYPT, &hSessionKey))
  30. {
  31. qDebug()<<"Error2";
  32. //Error("CryptGenKey");
  33. //return ;
  34. }
  35.  
  36. qDebug() << "Session key generated";
  37.  
  38. // Данные для шифрования
  39. char string[]="Test";
  40. DWORD count=strlen(string);
  41.  
  42. // Шифрование данных
  43. if (!CryptEncrypt(hSessionKey, 0, true, 0, (BYTE*)string,
  44. &count, strlen(string)))
  45. {
  46. //Error("CryptEncrypt");
  47. // return;
  48. }
  49.  
  50. qDebug() << "Encryption completed";
  51.  
  52. // Тестовый вывод на экран
  53. qDebug() << "Encrypted string: " << string;
  54.  
  55.  
  56. return a.exec();
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement