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

Method Encrypt

src/wallet/crypter.cpp:50–75  ·  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 EVP_CIPHER_CTX ctx;
62
63 bool fOk = true;
64
65 EVP_CIPHER_CTX_init(&ctx);
66 if (fOk) fOk = EVP_EncryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, chKey, chIV) != 0;
67 if (fOk) fOk = EVP_EncryptUpdate(&ctx, &vchCiphertext[0], &nCLen, &vchPlaintext[0], nLen) != 0;
68 if (fOk) fOk = EVP_EncryptFinal_ex(&ctx, (&vchCiphertext[0]) + nCLen, &nFLen) != 0;
69 EVP_CIPHER_CTX_cleanup(&ctx);
70
71 if (!fOk) return false;
72
73 vchCiphertext.resize(nCLen + nFLen);
74 return true;
75}
76
77bool CCrypter::Decrypt(const std::vector<unsigned char>& vchCiphertext, CKeyingMaterial& vchPlaintext)
78{

Callers 3

EncryptSecretFunction · 0.80
BOOST_FOREACHFunction · 0.80
EncryptWalletMethod · 0.80

Calls 2

resizeMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected