client-cpp  0.10.0
KeyUtils.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014-2016 CyberVision, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef KEYUTILS_HPP_
18 #define KEYUTILS_HPP_
19 
20 #include <botan/botan.h>
21 #include <string>
22 #include <utility>
23 #include <cstdint>
24 #include <memory>
25 #include <boost/scoped_array.hpp>
27 
28 namespace kaa {
29 
30 class KeyUtils {
31 public:
38  KeyPair generateKeyPair(std::size_t length);
39 
46  SessionKey generateSessionKey(std::size_t length);
47 
55  bool checkKeyPair(const KeyPair &keys);
56 
57  static PublicKey loadPublicKey(const std::string& fileName);
58 
59  static PrivateKey loadPrivateKey(const std::string& fileName);
60 
61  static KeyPair loadKeyPair(const std::string& pubFileName, const std::string& privFileName);
62 
63  static void saveKeyPair(const KeyPair& pair, const std::string& pubFileName, const std::string& privFileName);
64 
65  static void savePublicKey(const PublicKey& key, const std::string& pubFileName);
66 
67  static void savePrivateKey(const PrivateKey& key, const std::string& privFileName);
68 
69 private:
70  static void readFile(const std::string& fileName, boost::scoped_array<char>& buf, std::size_t& len);
71 
72 private:
73  Botan::AutoSeeded_RNG rng_;
74 };
75 
76 }
77 
78 #endif /* KEYUTILS_HPP_ */
Botan::secure_vector< std::uint8_t > PublicKey
static void savePublicKey(const PublicKey &key, const std::string &pubFileName)
SessionKey generateSessionKey(std::size_t length)
static KeyPair loadKeyPair(const std::string &pubFileName, const std::string &privFileName)
static PrivateKey loadPrivateKey(const std::string &fileName)
KeyPair generateKeyPair(std::size_t length)
bool checkKeyPair(const KeyPair &keys)
Botan::SymmetricKey SessionKey
static PublicKey loadPublicKey(const std::string &fileName)
static void savePrivateKey(const PrivateKey &key, const std::string &privFileName)
std::string PrivateKey
static void saveKeyPair(const KeyPair &pair, const std::string &pubFileName, const std::string &privFileName)