Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void tradingDialog::on_SaveKeys_clicked()
- {
- // Encryption properties store iv and password information
- EncryptionProperties props;
- // Generate a 256 bit random IV from 4 separate 64 bit numbers
- props.iv = crypto_random();
- props.iv2 = crypto_random();
- props.iv3 = crypto_random();
- props.iv4 = crypto_random();
- // What cipher function do we require?
- props.cipher = Algorithm::AES;
- // Qstring to string
- string password = ui->PasswordInput->text().toUtf8().constData();
- // the password used for encryption / decryption
- props.password = string(password);
- /*========== The main cryptostreampp usage ==========*/
- boost::filesystem::path pathAPI = GetDataDir() / "APIcache.txt";
- // Create a stream in output mode to create a brand new file called apicache.txt
- //CryptoStreamPP stream(pathAPI.string(), props, std::ios::out | std::ios::binary | std::ios::trunc);
- CryptoStreamPP stream(pathAPI.string(), props, std::ios::out | std::ios::binary | std::ios::trunc);
- // ------------------------------------------------------
- // NOTE:
- // After creating the stream, there will be a short pause
- // as the key stream is initialized. This accounts for
- // one million iterations of PBKDF2
- // ------------------------------------------------------
- // write to the stream as you would a normal fstream. Normally
- // you would write a buffer of char data. In this example,
- // we write a string which is basically the same thing.
- // Stream operator support to be properly added in future.
- // qstring to std string add space and convert to const char for stream
- const char* API = (ui->ApiKeyInput->text().toStdString() + ui->SecretKeyInput->text().toStdString()).c_str();
- stream.write(API, 64);
- // make sure stream is flushed before closing it
- stream.flush();
- stream.close();
- }
- void tradingDialog::on_LoadKeys_clicked()
- {
- // Encryption properties store iv and password information
- EncryptionProperties props;
- // Generate a 256 bit random IV from 4 separate 64 bit numbers
- props.iv = crypto_random();
- props.iv2 = crypto_random();
- props.iv3 = crypto_random();
- props.iv4 = crypto_random();
- // What cipher function do we require?
- props.cipher = Algorithm::AES;
- // Qstring to string
- string password = ui->PasswordInput->text().toUtf8().constData();
- // the password used for encryption / decryption
- props.password = string(password);
- boost::filesystem::path pathAPI = GetDataDir() / "APIcache.txt";
- // Create a stream in input mode to open a file named APIcache.txt
- CryptoStreamPP stream(pathAPI.string(), props, std::ios::in | std::ios::binary);
- // Read in a buffer of data
- {
- stream.seekg(0);
- char buffer[33];
- stream.read(buffer, 32);
- buffer[32] = '\0';
- // Should print out "api key 32 digit"
- std::ostringstream ApiKey;
- std::streambuf * old = std::cout.rdbuf(ApiKey.rdbuf());
- std::cout<<buffer;
- //stringstream to standard string to Qstring
- QString Key = QString::fromStdString(ApiKey.str());
- ui->ApiKeyInput->setText(Key);
- }
- stream.flush();
- // now seek to digit 32 and read in api secret
- {
- stream.seekg(32);
- char buffer[33];
- stream.read(buffer, 32);
- buffer[32] = '\0';
- // Should print out "api secret 32 digit"
- std::ostringstream ApiSecret;
- std::streambuf * old = std::cout.rdbuf(ApiSecret.rdbuf());
- std::cout<<buffer;
- //stringstream to standard string to Qstring
- QString Secret = QString::fromStdString(ApiSecret.str());
- ui->SecretKeyInput->setText(Secret);
- }
- stream.flush();
- stream.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement