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