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

Method Decrypt

src/wallet/crypter.cpp:76–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74}
75
76bool CCrypter::Decrypt(const vector<unsigned char>& vchCiphertext, CKeyingMaterial& vchPlaintext) {
77 if (!fKeySet)
78 return false;
79
80 // plaintext will always be equal to or lesser than length of ciphertext
81 int32_t nLen = vchCiphertext.size();
82 int32_t nPLen = nLen, nFLen = 0;
83
84 vchPlaintext = CKeyingMaterial(nPLen);
85
86 evp_cipher_ctx ctx(EVP_CIPHER_CTX_new());
87 if (!ctx) {
88 return false;
89 }
90
91 bool fOk = true;
92
93 if (fOk)
94 fOk = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, chKey, chIV);
95 if (fOk)
96 fOk = EVP_DecryptUpdate(ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen);
97 if (fOk)
98 fOk = EVP_DecryptFinal_ex(ctx, (&vchPlaintext[0]) + nPLen, &nFLen);
99
100 if (!fOk)
101 return false;
102
103 vchPlaintext.resize(nPLen + nFLen);
104 return true;
105}
106
107bool EncryptSecret(const CKeyingMaterial& vMasterKey, const CKeyingMaterial& vchPlaintext, const uint256& nIV,
108 vector<unsigned char>& vchCiphertext) {

Callers 3

DecryptSecretFunction · 0.45
UnlockMethod · 0.45

Calls 2

sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected