MCPcopy Create free account
hub / github.com/Snapchat/Valdi / encrypt

Method encrypt

valdi/src/valdi/runtime/Utils/DataEncryptor.cpp:21–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19}
20
21bool DataEncryptor::encrypt(const Byte* data, size_t length, ByteBuffer& out) const {
22 snap::utils::crypto::AesEncryptor::Iv iv;
23 RAND_bytes(reinterpret_cast<uint8_t*>(iv.data()), iv.size());
24
25 snap::utils::crypto::AesEncryptor encryptor(_key, iv);
26
27 auto encryptResult = encryptor.encrypt(toSpan(data, length));
28 if (!encryptResult) {
29 return false;
30 }
31
32 // Insert the IV at the front
33 out.append(iv.begin(), iv.end());
34
35 // Append the data after
36 out.append(encryptResult.value().data(), encryptResult.value().data() + encryptResult.value().size());
37
38 return true;
39}
40
41bool DataEncryptor::decrypt(const Byte* data, size_t length, ByteBuffer& out) const {
42 snap::utils::crypto::AesEncryptor::Iv iv;

Callers 2

TESTFunction · 0.45
storeMethod · 0.45

Calls 7

toSpanFunction · 0.85
appendMethod · 0.65
endMethod · 0.65
valueMethod · 0.65
dataMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45

Tested by 1

TESTFunction · 0.36