00001 // RSA public key encryption 00002 00003 #ifndef __UT_RSA__ 00004 #define __UT_RSA__ 00005 00006 #include "UT_API.h" 00007 #include "UT_VeryLong.h" 00008 00009 class UT_API UT_RSA_Public 00010 { 00011 public: 00012 UT_VeryLong myM; // My modulus 00013 UT_VeryLong myE; // My public exponent 00014 00015 // Requires 0 <= plain < m 00016 UT_VeryLong encrypt( const UT_VeryLong &plain ); 00017 void encrypt(unsigned char *dest, const unsigned char *src, 00018 unsigned &len); 00019 00020 void setE(const unsigned *e, int ewords); 00021 void setM(const unsigned *m, int mwords); 00022 void setE(UT_VeryLong &e) { myE = e; } 00023 void setM(UT_VeryLong &m) { myM = m; } 00024 }; 00025 00026 class UT_API UT_RSA_Private : public UT_RSA_Public 00027 { 00028 public: 00029 UT_VeryLong myD; // My private key 00030 UT_VeryLong decrypt(const UT_VeryLong &cipher); 00031 void decrypt(unsigned char *dest, const unsigned char *src, 00032 unsigned &len); 00033 00034 void setPassword(const char *passwd); 00035 // r1 and r2 should be null terminated random strings 00036 // each of length around 35 characters (for a 500 bit modulus) 00037 void create(const char *r1, const char *r2, const char *passwd); 00038 void setD(const unsigned *d, int dwords); 00039 void setD(UT_VeryLong &d) { myD = d; } 00040 00041 // Print code containing modulus and public/private keys 00042 void printCode(); 00043 }; 00044 00045 #endif 00046
1.5.9