00001
00002
00003
00004
00005
00006
00007
#ifndef __WVRSA_H
00008
#define __WVRSA_H
00009
00010
#include "wverror.h"
00011
#include "wvencoder.h"
00012
#include "wvencoderstream.h"
00013
00014
struct rsa_st;
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 class WvRSAKey :
public WvError
00026 {
00027
int errnum;
00028
WvString pub, prv;
00029
00030
void init(
WvStringParm keystr,
bool priv);
00031
static WvString hexifypub(
struct rsa_st *
rsa);
00032
static WvString hexifyprv(
struct rsa_st *rsa);
00033
00034
public:
00035 struct rsa_st *rsa;
00036
00037
WvRSAKey(
const WvRSAKey &k);
00038
WvRSAKey(
struct rsa_st *_rsa,
bool priv);
00039
WvRSAKey(
WvStringParm keystr,
bool priv);
00040
WvRSAKey(
int bits);
00041
00042
~WvRSAKey();
00043
00044 WvString private_str()
const
00045
{
return prv; }
00046 WvString public_str()
const
00047
{
return pub; }
00048 };
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 class WvRSAEncoder :
public WvEncoder
00063 {
00064
public:
00065 enum Mode {
00066
Encrypt,
00067
Decrypt,
00068
SignEncrypt,
00069
SignDecrypt
00070 };
00071
00072
00073
00074
00075
00076
00077
00078
00079
WvRSAEncoder(Mode mode,
const WvRSAKey &key);
00080
virtual ~WvRSAEncoder();
00081
00082
protected:
00083
virtual bool _encode(
WvBuf &in,
WvBuf &out,
bool flush);
00084
virtual bool _reset();
00085
00086
private:
00087 Mode mode;
00088
WvRSAKey key;
00089 size_t rsasize;
00090 };
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 class WvRSAStream :
public WvEncoderStream
00102 {
00103
public:
00104
WvRSAStream(
WvStream *_cloned,
00105
const WvRSAKey &_my_key,
const WvRSAKey &_their_key,
00106 WvRSAEncoder::Mode readmode = WvRSAEncoder::Decrypt,
00107 WvRSAEncoder::Mode writemode = WvRSAEncoder::Encrypt);
00108 virtual ~WvRSAStream() { }
00109 };
00110
00111
00112
#endif // __WVRSA_H