MCPcopy Create free account
hub / github.com/apache/nifi-minifi-cpp / encryptRaw

Function encryptRaw

libminifi/src/utils/EncryptionUtils.cpp:64–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62std::string EncryptionType::separator() { return "||"; }
63
64Bytes encryptRaw(const Bytes& plaintext, const Bytes& key, const Bytes& nonce) {
65 if (key.size() != EncryptionType::keyLength()) {
66 throw std::invalid_argument{"Expected key of " + std::to_string(EncryptionType::keyLength()) +
67 " bytes, but got " + std::to_string(key.size()) + " bytes during encryption"};
68 }
69 if (nonce.size() != EncryptionType::nonceLength()) {
70 throw std::invalid_argument{"Expected nonce of " + std::to_string(EncryptionType::nonceLength()) +
71 " bytes, but got " + std::to_string(nonce.size()) + " bytes during encryption"};
72 }
73
74 Bytes ciphertext_plus_mac(plaintext.size() + EncryptionType::macLength());
75 crypto_secretbox_easy(ciphertext_plus_mac.data(), plaintext.data(), plaintext.size(), nonce.data(), key.data());
76 return ciphertext_plus_mac;
77}
78
79std::string encrypt(const std::string& plaintext, const Bytes& key) {
80 Bytes nonce = randomBytes(EncryptionType::nonceLength());

Callers 2

encryptFunction · 0.85

Calls 2

to_stringFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected