---
title: llarp/config/key_manager.hpp

---

# llarp/config/key_manager.hpp



## Namespaces

| Name           |
| -------------- |
| **[llarp](Namespaces/namespacellarp.md)** <br>[crypto.hpp] |

## Classes

|                | Name           |
| -------------- | -------------- |
| struct | **[llarp::KeyManager](Classes/structllarp_1_1KeyManager.md)** <br>[KeyManager]() manages the cryptographic keys stored on disk for the local node.  |




## Source code

```cpp
#pragma once

#include <atomic>
#include "config.hpp"
#include <llarp/crypto/types.hpp>
#include <llarp/router_contact.hpp>

namespace llarp
{
  struct KeyManager
  {
    static bool
    backupFileByMoving(const fs::path& filepath);

    KeyManager();

    bool
    initialize(const llarp::Config& config, bool genIfAbsent, bool isSNode);

    bool
    getRouterContact(llarp::RouterContact& rc) const;

    bool
    needBackup() const
    {
      return m_needBackup;
    }

    llarp::SecretKey identityKey;
    llarp::SecretKey encryptionKey;
    llarp::SecretKey transportKey;

    fs::path m_rcPath;
    fs::path m_idKeyPath;
    fs::path m_encKeyPath;
    fs::path m_transportKeyPath;

   private:
    std::atomic_bool m_initialized;
    std::atomic_bool m_needBackup;

    bool
    backupKeyFilesByMoving() const;

    static bool
    loadOrCreateKey(
        fs::path filepath,
        llarp::SecretKey& key,
        std::function<void(llarp::SecretKey& key)> keygen);
  };

}  // namespace llarp
```


-------------------------------

Updated on 2022-09-10 at 18:17:15 +0000
