feisty meow concerns codebase 2.140
rsa_crypto.h
Go to the documentation of this file.
1#ifndef RSA_CRYPTO_CLASS
2#define RSA_CRYPTO_CLASS
3
4/*****************************************************************************\
5* *
6* Name : RSA public key encryption *
7* Author : Chris Koeritz *
8* *
9*******************************************************************************
10* Copyright (c) 2005-$now By Author. This program is free software; you can *
11* redistribute it and/or modify it under the terms of the GNU General Public *
12* License as published by the Free Software Foundation; either version 2 of *
13* the License or (at your option) any later version. This is online at: *
14* http://www.fsf.org/copyleft/gpl.html *
15* Please send any updates to: fred@gruntose.com *
16\*****************************************************************************/
17
18#include <basis/byte_array.h>
19#include <basis/contracts.h>
20
21// forward.
22//struct RSA;
23typedef struct rsa_st RSA;
24
25namespace crypto {
26
28
32class rsa_crypto : public virtual basis::nameable
33{
34public:
35 rsa_crypto(int key_size);
37
40 rsa_crypto(const basis::byte_array &key);
42
47 rsa_crypto(RSA *key);
49
50 rsa_crypto(const rsa_crypto &to_copy);
51
52 virtual ~rsa_crypto();
53
54 const rsa_crypto &operator = (const rsa_crypto &to_copy);
55
56 DEFINE_CLASS_NAME("rsa_crypto");
57
58 bool set_key(basis::byte_array &key);
60
64 bool set_key(RSA *key);
66
68 bool check_key(RSA *key);
70
71 bool public_encrypt(const basis::byte_array &source, basis::byte_array &target) const;
73
76 bool private_decrypt(const basis::byte_array &source, basis::byte_array &target) const;
78
79 bool private_encrypt(const basis::byte_array &source, basis::byte_array &target) const;
81
84 bool public_decrypt(const basis::byte_array &source, basis::byte_array &target) const;
86
87 bool public_key(basis::byte_array &pubkey) const;
89 bool private_key(basis::byte_array &privkey) const;
91
93 static RSA *generate_key(int key_size);
95
96private:
97 RSA *_key;
98};
99
100} //namespace.
101
102#endif
103
A very common template for a dynamic array of bytes.
Definition byte_array.h:36
Root object for any class that knows its own name.
Definition contracts.h:123
Supports public key encryption and decryption.
Definition rsa_crypto.h:33
const rsa_crypto & operator=(const rsa_crypto &to_copy)
bool public_encrypt(const basis::byte_array &source, basis::byte_array &target) const
encrypts "source" using our public key and stores it in "target".
bool set_key(basis::byte_array &key)
resets this object's key to "key".
bool private_key(basis::byte_array &privkey) const
makes a copy of the private key held here.
static RSA * generate_key(int key_size)
creates a random RSA key using the lower-level openssl methods.
bool private_decrypt(const basis::byte_array &source, basis::byte_array &target) const
decrypts "source" using our private key and stores it in "target".
bool public_decrypt(const basis::byte_array &source, basis::byte_array &target) const
decrypts "source" using our public key and stores it in "target".
DEFINE_CLASS_NAME("rsa_crypto")
bool check_key(RSA *key)
checks the RSA "key" provided for validity.
bool private_encrypt(const basis::byte_array &source, basis::byte_array &target) const
encrypts "source" using our private key and stores it in "target".
virtual ~rsa_crypto()
bool public_key(basis::byte_array &pubkey) const
makes a copy of the public key held here.
struct rsa_st RSA
Definition rsa_crypto.h:23