#include #include "aes.h" #include "base64.h" //TODO: remove #include "envelope.h" #include "rng.h" using namespace std; namespace Envelope{ bool safeKey(const string &key){ //checks against keys 0 and 1, because they don't undergo change in RSA int i; for(i=0;i<(int)key.size();i++)if(key[i]!=0)break; if(i==(int)key.size())return false; //key is 0 if(i==(int)key.size()-1&&key[i]==1)return false; //key is 1 return true; //fine } string encrypt(const string &data,const RSA::PublicKey &pubkey){ const int keylen=8; //256-bit CryptoRng crng; string key(4*keylen,'\0'); do { for(int i=0;i bytes; //bytes in little-endian order while(res!=0){ bytes.push_back(res.lowdigits()&0xff); res>>=8; } cerr<<"encrkey="<=0;i--)payload.push_back(bytes[i]); payload.push_back(bytes.size()>>8); payload.push_back((uint8_t)bytes.size()&0xff); return payload; } string decrypt(const string &data,const RSA::PrivateKey &privkey){ cerr<<"=== DECRYPT ==="<