feisty meow concerns codebase
2.140
|
Supports public key encryption and decryption. More...
#include <rsa_crypto.h>
Public Member Functions | |
rsa_crypto (int key_size) | |
constructs using a randomized private key of the "key_size". More... | |
rsa_crypto (const basis::byte_array &key) | |
constructs with the specified "key" as our private key. More... | |
rsa_crypto (RSA *key) | |
starts with a pre-existing "key" in the low-level form. More... | |
rsa_crypto (const rsa_crypto &to_copy) | |
virtual | ~rsa_crypto () |
const rsa_crypto & | operator= (const rsa_crypto &to_copy) |
DEFINE_CLASS_NAME ("rsa_crypto") | |
bool | set_key (basis::byte_array &key) |
resets this object's key to "key". More... | |
bool | set_key (RSA *key) |
sets our new "key". More... | |
bool | check_key (RSA *key) |
checks the RSA "key" provided for validity. More... | |
bool | public_encrypt (const basis::byte_array &source, basis::byte_array &target) const |
encrypts "source" using our public key and stores it in "target". More... | |
bool | private_decrypt (const basis::byte_array &source, basis::byte_array &target) const |
decrypts "source" using our private key and stores it in "target". More... | |
bool | private_encrypt (const basis::byte_array &source, basis::byte_array &target) const |
encrypts "source" using our private key and stores it in "target". More... | |
bool | public_decrypt (const basis::byte_array &source, basis::byte_array &target) const |
decrypts "source" using our public key and stores it in "target". More... | |
bool | public_key (basis::byte_array &pubkey) const |
makes a copy of the public key held here. More... | |
bool | private_key (basis::byte_array &privkey) const |
makes a copy of the private key held here. More... | |
Public Member Functions inherited from basis::nameable | |
virtual const char * | class_name () const =0 |
Returns the bare name of this class as a constant character pointer. More... | |
Static Public Member Functions | |
static RSA * | generate_key (int key_size) |
creates a random RSA key using the lower-level openssl methods. More... | |
Supports public key encryption and decryption.
This class uses the OpenSSL package's support for RSA encryption.
Definition at line 32 of file rsa_crypto.h.
crypto::rsa_crypto::rsa_crypto | ( | int | key_size | ) |
constructs using a randomized private key of the "key_size".
the "key_size" must be at least 1024 bits for acceptable security. smaller keys are considered insecure.
Definition at line 58 of file rsa_crypto.cpp.
crypto::rsa_crypto::rsa_crypto | ( | const basis::byte_array & | key | ) |
constructs with the specified "key" as our private key.
the "key" is used for encryption rather than generating a random one. the key is only valid if it was created with this class. also, if the key is a public key, then only the public_encryption and public_decryption methods will be available.
Definition at line 67 of file rsa_crypto.cpp.
References FUNCDEF, LOG, set_key(), and crypto::static_ssl_initializer().
crypto::rsa_crypto::rsa_crypto | ( | RSA * | key | ) |
starts with a pre-existing "key" in the low-level form.
Definition at line 78 of file rsa_crypto.cpp.
References FUNCDEF, LOG, set_key(), and crypto::static_ssl_initializer().
crypto::rsa_crypto::rsa_crypto | ( | const rsa_crypto & | to_copy | ) |
Definition at line 88 of file rsa_crypto.cpp.
References FUNCDEF, LOG, set_key(), and crypto::static_ssl_initializer().
|
virtual |
Definition at line 99 of file rsa_crypto.cpp.
bool crypto::rsa_crypto::check_key | ( | RSA * | key | ) |
checks the RSA "key" provided for validity.
Definition at line 139 of file rsa_crypto.cpp.
crypto::rsa_crypto::DEFINE_CLASS_NAME | ( | "rsa_crypto" | ) |
|
static |
creates a random RSA key using the lower-level openssl methods.
Definition at line 115 of file rsa_crypto.cpp.
References continuable_error, FUNCDEF, LOG, NULL_POINTER, static_class_name, and crypto::static_ssl_initializer().
const rsa_crypto & crypto::rsa_crypto::operator= | ( | const rsa_crypto & | to_copy | ) |
Definition at line 108 of file rsa_crypto.cpp.
References set_key().
bool crypto::rsa_crypto::private_decrypt | ( | const basis::byte_array & | source, |
basis::byte_array & | target | ||
) | const |
decrypts "source" using our private key and stores it in "target".
Definition at line 336 of file rsa_crypto.cpp.
References basis::array< contents >::access(), FUNCDEF, basis::array< contents >::last(), basis::array< contents >::length(), basis::array< contents >::reset(), and basis::array< contents >::zap().
Referenced by octopi::encryption_infoton::extract_response().
bool crypto::rsa_crypto::private_encrypt | ( | const basis::byte_array & | source, |
basis::byte_array & | target | ||
) | const |
encrypts "source" using our private key and stores it in "target".
private_encrypt and public_decrypt are also a pair. the trusted user with the private key can create encrypted chunks that anyone with the public key can decrypt.
Definition at line 362 of file rsa_crypto.cpp.
References basis::array< contents >::access(), FUNCDEF, basis::array< contents >::last(), basis::array< contents >::length(), and basis::array< contents >::reset().
bool crypto::rsa_crypto::private_key | ( | basis::byte_array & | privkey | ) | const |
makes a copy of the private key held here.
the private key should never be exposed to anyone else.
Definition at line 269 of file rsa_crypto.cpp.
References basis::array< contents >::access(), structures::attach(), FUNCDEF, basis::array< contents >::length(), and public_key().
Referenced by cromp::cromp_client::enable_encryption().
bool crypto::rsa_crypto::public_decrypt | ( | const basis::byte_array & | source, |
basis::byte_array & | target | ||
) | const |
decrypts "source" using our public key and stores it in "target".
Definition at line 385 of file rsa_crypto.cpp.
References basis::array< contents >::access(), FUNCDEF, basis::array< contents >::last(), basis::array< contents >::length(), basis::array< contents >::reset(), and basis::array< contents >::zap().
bool crypto::rsa_crypto::public_encrypt | ( | const basis::byte_array & | source, |
basis::byte_array & | target | ||
) | const |
encrypts "source" using our public key and stores it in "target".
public_encrypt and private_decrypt are a pair. an untrusted user can encrypt with the public key and only the possessor of the private key should be able to decrypt it.
Definition at line 313 of file rsa_crypto.cpp.
References basis::array< contents >::access(), FUNCDEF, basis::array< contents >::last(), basis::array< contents >::length(), and basis::array< contents >::reset().
Referenced by octopi::encryption_infoton::prepare_blowfish_key().
bool crypto::rsa_crypto::public_key | ( | basis::byte_array & | pubkey | ) | const |
makes a copy of the public key held here.
Definition at line 245 of file rsa_crypto.cpp.
References basis::array< contents >::access(), structures::attach(), FUNCDEF, and basis::WHACK().
Referenced by octopi::encryption_infoton::prepare_public_key(), and private_key().
bool crypto::rsa_crypto::set_key | ( | basis::byte_array & | key | ) |
resets this object's key to "key".
the key is only valid if this class created it. note: the "key" is destructively consumed during the set method; do not pass in your only copy.
Definition at line 145 of file rsa_crypto.cpp.
References basis::array< contents >::access(), continuable_error, structures::detach(), FUNCDEF, basis::array< contents >::length(), NULL_POINTER, and static_class_name.
Referenced by operator=(), and rsa_crypto().
bool crypto::rsa_crypto::set_key | ( | RSA * | key | ) |
sets our new "key".
this must be a valid key created via the RSA algorithms.
Definition at line 226 of file rsa_crypto.cpp.
References continuable_error, FUNCDEF, NULL_POINTER, and static_class_name.