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