client-cpp  0.6.1
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>
26 
27 namespace kaa {
28 
29 typedef std::pair<Botan::MemoryVector<std::uint8_t>, std::string> KeyPair;
30 
31 class KeyUtils {
32 public:
39  KeyPair generateKeyPair(std::size_t length);
40 
47  Botan::SymmetricKey generateSessionKey(std::size_t length);
48 
49  static Botan::MemoryVector<std::uint8_t> loadPublicKey(const std::string& fileName);
50 
51  static std::string loadPrivateKey(const std::string& fileName);
52 
53  static KeyPair loadKeyPair(const std::string& pubFileName, const std::string& privFileName);
54 
55  static void saveKeyPair(const KeyPair& pair, const std::string& pubFileName, const std::string& privFileName);
56 
57  static void savePublicKey(const Botan::MemoryVector<std::uint8_t>& key, const std::string& pubFileName);
58 
59  static void savePrivateKey(const std::string& key, const std::string& privFileName);
60 
61 private:
62  static void readFile(const std::string& fileName, boost::scoped_array<char>& buf, std::size_t& len);
63 
64 private:
65  Botan::AutoSeeded_RNG rng_;
66 };
67 
68 }
69 
70 #endif /* KEYUTILS_HPP_ */
std::pair< Botan::MemoryVector< std::uint8_t >, std::string > KeyPair
Definition: KeyUtils.hpp:29
static void savePublicKey(const Botan::MemoryVector< std::uint8_t > &key, const std::string &pubFileName)
static KeyPair loadKeyPair(const std::string &pubFileName, const std::string &privFileName)
KeyPair generateKeyPair(std::size_t length)
static Botan::MemoryVector< std::uint8_t > loadPublicKey(const std::string &fileName)
static std::string loadPrivateKey(const std::string &fileName)
Botan::SymmetricKey generateSessionKey(std::size_t length)
static void savePrivateKey(const std::string &key, const std::string &privFileName)
static void saveKeyPair(const KeyPair &pair, const std::string &pubFileName, const std::string &privFileName)