client-cpp  0.6.1
RsaEncoderDecoder.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 RSAENCODERDECODER_HPP_
18 #define RSAENCODERDECODER_HPP_
19 
22 #include <botan/rsa.h>
23 #include <cstdint>
24 #include <memory>
25 
26 namespace kaa {
27 
29 public:
30  RsaEncoderDecoder(const Botan::MemoryVector<std::uint8_t>& pubKey,
31  const std::string& privKey,
32  const Botan::MemoryVector<std::uint8_t>& remoteKey);
34 
35  Botan::SecureVector<std::uint8_t> getEncodedSessionKey();
36  std::string encodeData(const std::uint8_t *data, std::size_t size);
37  std::string decodeData(const std::uint8_t *data, std::size_t size);
38  Botan::SecureVector<std::uint8_t> signData(const std::uint8_t *data, std::size_t size);
39  bool verifySignature(const std::uint8_t *data, std::size_t len, const std::uint8_t *sig, std::size_t sigLen);
40 
41 private:
42  std::string cipherPipe(const std::uint8_t *data, std::size_t size, Botan::Cipher_Dir dir);
43 
44 private:
45  Botan::AutoSeeded_RNG rng_;
46  std::unique_ptr<Botan::X509_PublicKey> pubKey_;
47  std::unique_ptr<Botan::PKCS8_PrivateKey> privKey_;
48  std::unique_ptr<Botan::X509_PublicKey> remoteKey_;
49 
50  Botan::SymmetricKey sessionKey_;
51 };
52 
53 }
54 
55 
56 #endif /* RSAENCODERDECODER_HPP_ */
std::string decodeData(const std::uint8_t *data, std::size_t size)
RsaEncoderDecoder(const Botan::MemoryVector< std::uint8_t > &pubKey, const std::string &privKey, const Botan::MemoryVector< std::uint8_t > &remoteKey)
Botan::SecureVector< std::uint8_t > signData(const std::uint8_t *data, std::size_t size)
Botan::SecureVector< std::uint8_t > getEncodedSessionKey()
bool verifySignature(const std::uint8_t *data, std::size_t len, const std::uint8_t *sig, std::size_t sigLen)
std::string encodeData(const std::uint8_t *data, std::size_t size)