2016-03-23 18:12:07 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-03-23 18:12:07 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-03-23 18:12:07 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace MTP {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
// this class holds an RSA public key and can encrypt fixed-size messages with it
|
|
|
|
class RSAPublicKey final {
|
|
|
|
public:
|
2017-03-23 16:11:35 +00:00
|
|
|
RSAPublicKey() = default;
|
2017-04-24 12:16:38 +00:00
|
|
|
RSAPublicKey(base::const_byte_span nBytes, base::const_byte_span eBytes);
|
2017-03-23 16:11:35 +00:00
|
|
|
RSAPublicKey(RSAPublicKey &&other) = default;
|
|
|
|
RSAPublicKey(const RSAPublicKey &other) = default;
|
|
|
|
RSAPublicKey &operator=(RSAPublicKey &&other) = default;
|
|
|
|
RSAPublicKey &operator=(const RSAPublicKey &other) = default;
|
2016-03-23 18:12:07 +00:00
|
|
|
|
2017-12-08 15:24:09 +00:00
|
|
|
// key in "-----BEGIN RSA PUBLIC KEY----- ..." format
|
|
|
|
// or in "-----BEGIN PUBLIC KEY----- ..." format
|
|
|
|
explicit RSAPublicKey(base::const_byte_span key);
|
|
|
|
|
2016-03-23 18:12:07 +00:00
|
|
|
bool isValid() const;
|
|
|
|
uint64 getFingerPrint() const;
|
2017-04-24 12:16:38 +00:00
|
|
|
base::byte_vector getN() const;
|
|
|
|
base::byte_vector getE() const;
|
2016-03-23 18:12:07 +00:00
|
|
|
|
|
|
|
// data has exactly 256 chars to be encrypted
|
2017-04-24 12:16:38 +00:00
|
|
|
base::byte_vector encrypt(base::const_byte_span data) const;
|
2016-03-23 18:12:07 +00:00
|
|
|
|
2017-06-26 17:38:16 +00:00
|
|
|
// data has exactly 256 chars to be decrypted
|
|
|
|
base::byte_vector decrypt(base::const_byte_span data) const;
|
|
|
|
|
2016-03-23 18:12:07 +00:00
|
|
|
private:
|
2017-03-23 16:11:35 +00:00
|
|
|
class Private;
|
|
|
|
std::shared_ptr<Private> _private;
|
2016-03-23 18:12:07 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace MTP
|