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