| 88 | } |
| 89 | |
| 90 | bool CCrypter::Decrypt(const std::vector<unsigned char>& vchCiphertext, CKeyingMaterial& vchPlaintext) const |
| 91 | { |
| 92 | if (!fKeySet) |
| 93 | return false; |
| 94 | |
| 95 | // plaintext will always be equal to or lesser than length of ciphertext |
| 96 | int nLen = vchCiphertext.size(); |
| 97 | |
| 98 | vchPlaintext.resize(nLen); |
| 99 | |
| 100 | AES256CBCDecrypt dec(vchKey.data(), vchIV.data(), true); |
| 101 | nLen = dec.Decrypt(vchCiphertext.data(), vchCiphertext.size(), vchPlaintext.data()); |
| 102 | if(nLen == 0) |
| 103 | return false; |
| 104 | vchPlaintext.resize(nLen); |
| 105 | return true; |
| 106 | } |
| 107 | |
| 108 | bool EncryptSecret(const CKeyingMaterial& vMasterKey, const CKeyingMaterial &vchPlaintext, const uint256& nIV, std::vector<unsigned char> &vchCiphertext) |
| 109 | { |