#include <pke.hpp>
Definition at line 19 of file pke.hpp.
◆ public_key() [1/4]
fc::public_key::public_key |
( |
| ) |
|
◆ public_key() [2/4]
fc::public_key::public_key |
( |
const bytes & | d | ) |
|
|
explicit |
Definition at line 35 of file pke.cpp.
36 :my( std::make_shared<detail::pke_impl>() )
37 {
38 string pem = "-----BEGIN RSA PUBLIC KEY-----\n";
40 for( size_t i = 0; i < b64.size(); i += 64 )
41 pem += b64.substr( i, 64 ) + "\n";
42 pem += "-----END RSA PUBLIC KEY-----\n";
43
44
45 BIO* mem = (BIO*)BIO_new_mem_buf( (void*)pem.c_str(), pem.size() );
46 my->rsa = PEM_read_bio_RSAPublicKey(mem, NULL, NULL, NULL );
47 BIO_free(mem);
48 }
std::string base64_encode(unsigned char const *bytes_to_encode, unsigned int in_len)
◆ public_key() [3/4]
fc::public_key::public_key |
( |
const public_key & | k | ) |
|
◆ public_key() [4/4]
Definition at line 54 of file pke.cpp.
55 :my(std::move(k.my))
56 {
57 }
◆ ~public_key()
fc::public_key::~public_key |
( |
| ) |
|
◆ decrypt()
bytes fc::public_key::decrypt |
( |
const bytes & | in | ) |
const |
Definition at line 117 of file pke.cpp.
118 {
120 bytes out( RSA_size(my->rsa) );
121 int rtn = RSA_public_decrypt( in.size(),
122 (unsigned char*)in.data(),
123 (unsigned char*)out.data(),
124 my->rsa, RSA_PKCS1_OAEP_PADDING );
125 if( rtn >= 0 ) {
126 out.resize(rtn);
127 return out;
128 }
130 }
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
std::vector< char > bytes
◆ encrypt() [1/2]
bytes fc::public_key::encrypt |
( |
const bytes & | in | ) |
const |
Definition at line 102 of file pke.cpp.
103 {
105 bytes out( RSA_size(my->rsa) );
106 int rtn = RSA_public_encrypt( in.size(),
107 (unsigned char*)in.data(),
108 (unsigned char*)out.data(),
109 my->rsa, RSA_PKCS1_OAEP_PADDING );
110 fc::cerr<<"rtn: "<<rtn<<"\n";
111 if( rtn >= 0 ) {
112 out.resize(rtn);
113 return out;
114 }
116 }
◆ encrypt() [2/2]
bytes fc::public_key::encrypt |
( |
const char * | data, |
|
|
size_t | len ) const |
Definition at line 87 of file pke.cpp.
88 {
90 bytes out( RSA_size(my->rsa) );
91 int rtn = RSA_public_encrypt(
l,
92 (unsigned char*)b,
93 (unsigned char*)out.data(),
94 my->rsa, RSA_PKCS1_OAEP_PADDING );
95 if( rtn >= 0 ) {
96 out.resize(rtn);
97 return out;
98 }
100 }
◆ operator bool()
fc::public_key::operator bool |
( |
| ) |
const |
◆ operator=() [1/2]
Definition at line 61 of file pke.cpp.
62 {
63 my =
p.my;
return *
this;
64 }
◆ operator=() [2/2]
Definition at line 65 of file pke.cpp.
66 {
67 my = std::move(
p.my);
return *
this;
68 }
◆ serialize()
bytes fc::public_key::serialize |
( |
| ) |
const |
Definition at line 132 of file pke.cpp.
133 {
135 if( !my ) { return ba; }
136
137 BIO *mem = BIO_new(BIO_s_mem());
138 int e = PEM_write_bio_RSAPublicKey( mem, my->rsa );
139 if( e != 1 )
140 {
141 BIO_free(mem);
143 }
144 char* dat;
145 uint32_t l = BIO_get_mem_data( mem, &dat );
146
147 fc::stringstream
ss(
string( dat,
l ) );
148 fc::stringstream
key;
150 fc::getline( ss, tmp );
151 fc::getline( ss, tmp );
152 while( tmp.size() && tmp[0] != '-' )
153 {
154 key << tmp;
155 fc::getline( ss, tmp );
156 }
157 auto str = key.str();
160
161 BIO_free(mem);
162 return ba;
163 }
static const Segment ss(Segment::ss)
std::string base64_decode(const std::string &encoded_string)
◆ verify() [1/3]
bool fc::public_key::verify |
( |
const sha1 & | digest, |
|
|
const array< char, 2048/8 > & | sig ) const |
Definition at line 69 of file pke.cpp.
70 {
71 return 0 != RSA_verify( NID_sha1, (
const uint8_t*)&
digest, 20,
72 (
uint8_t*)&sig, 2048/8, my->rsa );
73 }
fc::sha256 digest(const T &value)
◆ verify() [2/3]
bool fc::public_key::verify |
( |
const sha1 & | digest, |
|
|
const signature & | sig ) const |
Definition at line 75 of file pke.cpp.
76 {
77 static_assert( sig.size() == 2048/8, "" );
78 return 0 != RSA_verify( NID_sha1, (
const uint8_t*)&
digest, 20,
80 }
const char * data() const
◆ verify() [3/3]
bool fc::public_key::verify |
( |
const sha256 & | digest, |
|
|
const signature & | sig ) const |
Definition at line 81 of file pke.cpp.
82 {
83 static_assert( sig.size() == 2048/8, "" );
84 return 0 != RSA_verify( NID_sha256, (
const uint8_t*)&
digest, 32,
86 }
◆ generate_key_pair
Definition at line 329 of file pke.cpp.
330 {
331 static bool init =
true;
332 if(
init ) { ERR_load_crypto_strings();
init =
false; }
333
334 pub.my = std::make_shared<detail::pke_impl>();
336 pub.my->rsa = RSA_generate_key( 2048, 65537, NULL, NULL );
337 }
The documentation for this class was generated from the following files:
- libraries/fc/include/fc/crypto/pke.hpp
- libraries/fc/src/crypto/pke.cpp