| 72 | } |
| 73 | |
| 74 | bool CCrypter::Encrypt(const CKeyingMaterial& vchPlaintext, std::vector<unsigned char> &vchCiphertext) const |
| 75 | { |
| 76 | if (!fKeySet) |
| 77 | return false; |
| 78 | |
| 79 | // max ciphertext len for a n bytes of plaintext is |
| 80 | // n + AES_BLOCKSIZE bytes |
| 81 | vchCiphertext.resize(vchPlaintext.size() + AES_BLOCKSIZE); |
| 82 | |
| 83 | AES256CBCEncrypt enc(vchKey.data(), vchIV.data(), true); |
| 84 | size_t nLen = enc.Encrypt(&vchPlaintext[0], vchPlaintext.size(), vchCiphertext.data()); |
| 85 | if(nLen < vchPlaintext.size()) |
| 86 | return false; |
| 87 | vchCiphertext.resize(nLen); |
| 88 | |
| 89 | return true; |
| 90 | } |
| 91 | |
| 92 | bool CCrypter::Decrypt(const std::vector<unsigned char>& vchCiphertext, CKeyingMaterial& vchPlaintext) const |
| 93 | { |