MCPcopy Create free account
hub / github.com/LUX-Core/lux / Encrypt

Method Encrypt

src/crypter.cpp:50–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48}
49
50bool CCrypter::Encrypt(const CKeyingMaterial& vchPlaintext, std::vector<unsigned char>& vchCiphertext)
51{
52 if (!fKeySet)
53 return false;
54
55 // max ciphertext len for a n bytes of plaintext is
56 // n + AES_BLOCK_SIZE - 1 bytes
57 int nLen = vchPlaintext.size();
58 int nCLen = nLen + AES_BLOCK_SIZE, nFLen = 0;
59 vchCiphertext = std::vector<unsigned char>(nCLen);
60
61 bool fOk = true;
62
63 EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
64 if (fOk) fOk = EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, chKey, chIV) != 0;
65 if (fOk) fOk = EVP_EncryptUpdate(ctx, &vchCiphertext[0], &nCLen, &vchPlaintext[0], nLen) != 0;
66 if (fOk) fOk = EVP_EncryptFinal_ex(ctx, (&vchCiphertext[0]) + nCLen, &nFLen) != 0;
67 EVP_CIPHER_CTX_free(ctx);
68
69 if (!fOk) return false;
70
71 vchCiphertext.resize(nCLen + nFLen);
72 return true;
73}
74
75bool CCrypter::Decrypt(const std::vector<unsigned char>& vchCiphertext, CKeyingMaterial& vchPlaintext)
76{

Callers 3

EncryptSecretFunction · 0.45
EncryptWalletMethod · 0.45

Calls 2

sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected