Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <Windows.h>
- #include <wincrypt.h>
- #include <string>
- #include <iomanip>
- #include <iostream>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "RUS");
- string nameC;
- cout << "Введите имя контейнера: ";
- cin >> nameC;
- HCRYPTKEY hKey;
- HCRYPTPROV hProv;
- LPCSTR Container = nameC.c_str();
- if (CryptAcquireContextA(&hProv, Container, NULL, PROV_RSA_FULL, 0))
- {
- cout << "Контейнер " << Container << " существует" << endl;
- jump:
- if (CryptGetUserKey(hProv, AT_KEYEXCHANGE, &hKey))
- {
- cout << "Ключ извлечен" << endl;
- CryptDestroyKey(hKey);
- }
- else
- {
- if (CryptGenKey(hProv, CALG_RSA_KEYX, CRYPT_EXPORTABLE, &hKey))
- {
- cout << "Ключ создан" << endl;
- CryptDestroyKey(hKey);
- }
- else
- {
- cerr << "Ошибка при создании ключа: " << GetLastError();
- if (hKey) CryptDestroyKey(hKey);
- }
- }
- }
- else
- {
- if (CryptAcquireContextA(&hProv, Container, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET))
- {
- cout << "Контейнер " << Container << " был создан" << endl;
- goto jump;
- }
- else
- {
- cerr << "Ошибка при создании контейнера: " << GetLastError();
- }
- }
- CryptReleaseContext(hProv, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment