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
|
|
|
|
|
2018-03-27 12:16:00 +00:00
|
|
|
#include "base/bytes.h"
|
|
|
|
|
2019-12-02 13:10:19 +00:00
|
|
|
namespace MTP::details {
|
2016-03-23 18:12:07 +00:00
|
|
|
|
|
|
|
// 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;
|
2018-03-27 12:16:00 +00:00
|
|
|
RSAPublicKey(bytes::const_span nBytes, bytes::const_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
|
2018-03-27 12:16:00 +00:00
|
|
|
explicit RSAPublicKey(bytes::const_span key);
|
2017-12-08 15:24:09 +00:00
|
|
|
|
2019-11-13 14:12:04 +00:00
|
|
|
[[nodiscard]] bool empty() const;
|
|
|
|
[[nodiscard]] bool valid() const;
|
|
|
|
[[nodiscard]] uint64 fingerprint() const;
|
|
|
|
[[nodiscard]] bytes::vector getN() const;
|
|
|
|
[[nodiscard]] bytes::vector getE() const;
|
2016-03-23 18:12:07 +00:00
|
|
|
|
|
|
|
// data has exactly 256 chars to be encrypted
|
2019-11-13 14:12:04 +00:00
|
|
|
[[nodiscard]] bytes::vector encrypt(bytes::const_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
|
2019-11-13 14:12:04 +00:00
|
|
|
[[nodiscard]] bytes::vector decrypt(bytes::const_span data) const;
|
2017-06-26 17:38:16 +00:00
|
|
|
|
2018-04-12 15:45:04 +00:00
|
|
|
// data has lequal than 215 chars to be decrypted
|
2019-11-13 14:12:04 +00:00
|
|
|
[[nodiscard]] bytes::vector encryptOAEPpadding(bytes::const_span data) const;
|
2018-04-12 15:45:04 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-12-02 13:10:19 +00:00
|
|
|
} // namespace MTP::details
|