* @brief Key::PublicKeyHash * Computes a short, human-readable (e.g. asciif-ied hex) hash for a given * public key. Serves a purpose of easy identification keys in multiplayer * overview, multiplayer settings. * * In particular, any of digest functions applied to a standardised key * representation, like PEM, will be sufficient. * * @return returns a string
| 167 | * @return returns a string containing key hash. |
| 168 | */ |
| 169 | std::string Key::PublicKeyHash() |
| 170 | { |
| 171 | try |
| 172 | { |
| 173 | std::string key = PublicKeyString(); |
| 174 | if (key.empty()) |
| 175 | { |
| 176 | throw std::runtime_error("No key found"); |
| 177 | } |
| 178 | auto hash = Crypt::SHA1(key.c_str(), key.size()); |
| 179 | return String::StringFromHex(hash); |
| 180 | } |
| 181 | catch (const std::exception& e) |
| 182 | { |
| 183 | LOG_ERROR("Failed to create hash of public key: %s", e.what()); |
| 184 | } |
| 185 | return {}; |
| 186 | } |
| 187 | |
| 188 | bool Key::Sign(const uint8_t* md, const size_t len, std::vector<uint8_t>& signature) const |
| 189 | { |
no test coverage detected