@@ -195,9 +195,12 @@ EncryptedKey EncryptionManager::EncryptKey(RocksdbSequence &&k) const {
195195}
196196EncryptedValue EncryptionManager::EncryptValue (const std::string &shard_name,
197197 RocksdbSequence &&v) {
198- const unsigned char *nonce = this ->global_nonce_ .get ();
198+ unsigned char *nonce = new unsigned char [NONCE_SIZE ];
199+ randombytes_buf (nonce, NONCE_SIZE );
199200 const unsigned char *key = this ->GetOrCreateUserKey (shard_name);
200- return Cipher (Encrypt (v.Data (), nonce, key));
201+ std::string nonce_str (reinterpret_cast <char *>(nonce), NONCE_SIZE );
202+ std::string cipher_str = Encrypt (v.Data (), nonce, key);
203+ return Cipher (nonce_str + cipher_str);
201204}
202205
203206// Decryption of records.
@@ -212,9 +215,12 @@ RocksdbSequence EncryptionManager::DecryptKey(EncryptedKey &&k) const {
212215}
213216RocksdbSequence EncryptionManager::DecryptValue (const std::string &shard_name,
214217 EncryptedValue &&v) const {
215- const unsigned char *nonce = this ->global_nonce_ .get ();
218+ std::string str = v.Release ();
219+ const char *ptr = str.data ();
220+ const unsigned char *nonce = reinterpret_cast <const unsigned char *>(ptr);
216221 const unsigned char *key = this ->GetUserKey (shard_name);
217- return RocksdbSequence (Decrypt (v.Data (), nonce, key));
222+ rocksdb::Slice cipher (ptr + NONCE_SIZE , str.size () - NONCE_SIZE );
223+ return RocksdbSequence (Decrypt (cipher, nonce, key));
218224}
219225
220226// Encrypts a key for use with rocksdb Seek.
0 commit comments