wvrsa.h

00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Tunnel Vision Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  *
00005  * RSA cryptography abstractions.
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 
00025 class WvRSAKey : public WvErrorBase
00026 {
00027     WvString pub, prv;
00028 
00029     void init(WvStringParm keystr, bool priv);
00030     static WvString hexifypub(struct rsa_st *rsa);
00031     static WvString hexifyprv(struct rsa_st *rsa);
00032 
00033 public:
00034     struct rsa_st *rsa;
00035 
00036     WvRSAKey(const WvRSAKey &k);
00037     WvRSAKey(struct rsa_st *_rsa, bool priv); // note: takes ownership
00038 
00042     WvRSAKey(WvStringParm keystr, bool priv);
00043 
00047     WvRSAKey(int bits);
00048     
00049     ~WvRSAKey();
00050     
00051     virtual bool isok() const;
00052     
00058     WvString private_str() const
00059         { return prv; }
00060 
00064     WvString public_str() const
00065         { return pub; }
00066     
00071     WvString getpem(bool privkey);
00072 
00073 };
00074 
00075 
00087 class WvRSAEncoder : public WvEncoder
00088 {
00089 public:
00090     enum Mode {
00091         Encrypt,     
00092         Decrypt,     
00093         SignEncrypt, 
00094         SignDecrypt  
00095     };
00096 
00104     WvRSAEncoder(Mode mode, const WvRSAKey &key);
00105     virtual ~WvRSAEncoder();
00106 
00107 protected:
00108     virtual bool _encode(WvBuf &in, WvBuf &out, bool flush);
00109     virtual bool _reset(); // supported
00110 
00111 private:
00112     Mode mode;
00113     WvRSAKey key;
00114     size_t rsasize;
00115 };
00116 
00117 
00126 class WvRSAStream : public WvEncoderStream
00127 {
00128 public:
00129     WvRSAStream(WvStream *_cloned,
00130         const WvRSAKey &_my_key, const WvRSAKey &_their_key, 
00131         WvRSAEncoder::Mode readmode = WvRSAEncoder::Decrypt,
00132         WvRSAEncoder::Mode writemode = WvRSAEncoder::Encrypt);
00133     virtual ~WvRSAStream() { }
00134 };
00135 
00136 
00137 #endif // __WVRSA_H

Generated on Wed Jul 12 17:53:21 2006 for WvStreams by  doxygen 1.4.7