Кодирование / декодирование не выполняется в Linux
Я ищу немного помощи с моими функциями кодирования / декодирования на кроссплатформенных платформах. В настоящее время код работает в ОС Windows, но не работает в Linux. В настоящее время это не проверено на Mac.
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.
// qstrings to utf8, add to byteArray and convert to const char for stream
const QByteArray byteArray = (ui->ApiKeyInput->text().toUtf8() + ui->SecretKeyInput->text().toUtf8());
const char *API = byteArray.constData();
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
{
QString Key = "";
stream.seekg(0);
char buffer[33];
stream.read(buffer, 32);
buffer[32] = '\0';
// Should print out "api key 32 digit"
Key = buffer;
ui->ApiKeyInput->setText(Key);
}
stream.flush();
// now seek to digit 32 and read in api secret
{
QString Secret = "";
stream.seekg(32);
char buffer[33];
stream.read(buffer, 32);
buffer[32] = '\0';
// Should print out "api secret 32 digit"
Secret = buffer;
ui->SecretKeyInput->setText(Secret);
}
stream.flush();
stream.close();
}
При печати "пароль" и "API" в "on_SaveKeys_clicked()". Оба верны.
При печати "пароля" в "on_LoadKeys_clicked()" это правильно.
При печати "Key" в "on_LoadKeys_clicked()" это неверно.
При печати "Secret" в "on_LoadKeys_clicked()" это неверно.
CryptoStreamPP можно найти по адресу https://github.com/benhj/CryptoStreamPP/tree/master/cryptostreampp