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

Method Decrypt

src/wallet/crypter.cpp:77–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

DecryptSecretFunction · 0.80
BOOST_FOREACHFunction · 0.80

Calls 2

resizeMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected