tdesktop/Telegram/SourceFiles/mtproto/details/mtproto_rsa_public_key.h

50 lines
1.5 KiB
C
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "base/bytes.h"
2019-12-02 13:10:19 +00:00
namespace MTP::details {
// this class holds an RSA public key and can encrypt fixed-size messages with it
class RSAPublicKey final {
public:
RSAPublicKey() = default;
RSAPublicKey(bytes::const_span nBytes, bytes::const_span eBytes);
RSAPublicKey(RSAPublicKey &&other) = default;
RSAPublicKey(const RSAPublicKey &other) = default;
RSAPublicKey &operator=(RSAPublicKey &&other) = default;
RSAPublicKey &operator=(const RSAPublicKey &other) = default;
2017-12-08 15:24:09 +00:00
// key in "-----BEGIN RSA PUBLIC KEY----- ..." format
// or in "-----BEGIN PUBLIC KEY----- ..." format
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;
// 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;
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
private:
class Private;
std::shared_ptr<Private> _private;
};
2019-12-02 13:10:19 +00:00
} // namespace MTP::details