client-cpp  0.7.0
KeyUtils.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014 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 
48  static PublicKey loadPublicKey(const std::string& fileName);
49 
50  static PrivateKey loadPrivateKey(const std::string& fileName);
51 
52  static KeyPair loadKeyPair(const std::string& pubFileName, const std::string& privFileName);
53 
54  static void saveKeyPair(const KeyPair& pair, const std::string& pubFileName, const std::string& privFileName);
55 
56  static void savePublicKey(const PublicKey& key, const std::string& pubFileName);
57 
58  static void savePrivateKey(const PrivateKey& key, const std::string& privFileName);
59 
60 private:
61  static void readFile(const std::string& fileName, boost::scoped_array<char>& buf, std::size_t& len);
62 
63 private:
64  Botan::AutoSeeded_RNG rng_;
65 };
66 
67 }
68 
69 #endif /* KEYUTILS_HPP_ */
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)
Botan::SymmetricKey SessionKey
static PublicKey loadPublicKey(const std::string &fileName)
static void savePrivateKey(const PrivateKey &key, const std::string &privFileName)
std::string PrivateKey
Botan::MemoryVector< std::uint8_t > PublicKey
static void saveKeyPair(const KeyPair &pair, const std::string &pubFileName, const std::string &privFileName)