| 77 | } |
| 78 | |
| 79 | std::string encrypt(const std::string& plaintext, const Bytes& key) { |
| 80 | Bytes nonce = randomBytes(EncryptionType::nonceLength()); |
| 81 | Bytes ciphertext_plus_mac = encryptRaw(stringToBytes(plaintext), key, nonce); |
| 82 | |
| 83 | std::string nonce_base64 = utils::StringUtils::to_base64(nonce); |
| 84 | std::string ciphertext_plus_mac_base64 = utils::StringUtils::to_base64(ciphertext_plus_mac); |
| 85 | return nonce_base64 + EncryptionType::separator() + ciphertext_plus_mac_base64; |
| 86 | } |
| 87 | |
| 88 | Bytes decryptRaw(const Bytes& input, const Bytes& key, const Bytes& nonce) { |
| 89 | if (key.size() != EncryptionType::keyLength()) { |
no test coverage detected