代码拉取完成,页面将自动刷新
同步操作将从 qingfengfumeng/文件软硬件加解密平台 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#ifndef RSA_H
#define RSA_H
#pragma once
#include<iostream>
#include<boost/multiprecision/cpp_int.hpp>
#include<boost/algorithm/string.hpp>
#include<boost/multiprecision/random.hpp>
#include<boost/multiprecision/miller_rabin.hpp>
#include<fstream>
#include<vector>
#include<time.h>
using namespace std;
namespace br = boost::random;
namespace bm = boost::multiprecision;
#define NUMBER 128 // Temporary buffer size
#define PUBLIC_KEY_PATH "public_key.txt" // Store key n, e,d
#define PRIVATE_KEY_PATH "private_key.txt" // Store key n, e,d
#define SIZE 128 // Control the random number size
typedef struct
{
bm::int1024_t mkey_e; // public key e
bm::int1024_t mkey_d; // private key d
bm::int1024_t mkey_n; // n = p * q
}Key;
class RSA
{
public:
RSA();
// Generate random key
void genKeys(std::string publickey_file, std::string privatekey_file);
// Generate a key or read an existing key
void getPublicKey(std::string filename);
// Generate a key or read an existing key
void getPrivateKey(std::string filename);
// Encrypt the file
bool encrypt_file(const std::string filename, const std::string outname);
// Decrypt the file
bool decrypt_file(const std::string filename, const std::string outname);
private:
Key mKey;
// prime detection
bool isPrime(bm::int1024_t num);
// get a prime
bm::int1024_t getPrime();
// get key n
bm::int1024_t getKey_n(bm::int1024_t p, bm::int1024_t q);
//get euler function f(n)
bm::int1024_t getFn(bm::int1024_t p, bm::int1024_t q);
// get public key
bm::int1024_t getKey_e(bm::int1024_t euler);
// extended Euclidean algorithm
void exGcd(bm::int1024_t a, bm::int1024_t b, bm::int1024_t* x, bm::int1024_t* y);
// get private key
bm::int1024_t getKey_d(bm::int1024_t key_e, bm::int1024_t euler);
// get the greatest common divisor
bm::int1024_t getGcd(bm::int1024_t n1, bm::int1024_t n2);
// Fast Modular Exponentiation
bm::int1024_t fastExp(bm::int1024_t data, bm::int1024_t key, bm::int1024_t key_n);
};
#endif // RSA_H
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。