aboutsummaryrefslogtreecommitdiff
path: root/rsa.h
blob: f931ab32b7f618b9cb8e03dbe799ad68e6beb48b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#pragma once

#include <string>
#include <utility>
#include "bigint.h"

namespace RSA{

	struct PublicKey{
		Bigint mod,exp;
	};

	struct PrivateKey{
		PublicKey pub;
		Bigint pexp;
	};

	Bigint encrypt(Bigint msg,const PublicKey &key);
	Bigint decrypt(Bigint msg,const PrivateKey &key);

	PrivateKey genkey(int nbits); //nbits is target number of bits of modulus
	PrivateKey genkey(int nbits,const std::string &password); //generates key seeded by password

	std::pair<std::string,std::string> exportkey(const PrivateKey&); //returns {pub,priv}
	PrivateKey importkey(const std::string &pub,const std::string &priv);

}