MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / Encrypt

Method Encrypt

src/wallet/crypter.cpp:45–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 3

EncryptSecretFunction · 0.45
EncryptWalletMethod · 0.45

Calls 2

sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected