diff options
Diffstat (limited to 'envelope')
-rwxr-xr-x | envelope/envelope | bin | 0 -> 121056 bytes | |||
-rw-r--r-- | envelope/main.cpp | 23 |
2 files changed, 20 insertions, 3 deletions
diff --git a/envelope/envelope b/envelope/envelope Binary files differnew file mode 100755 index 0000000..599c263 --- /dev/null +++ b/envelope/envelope diff --git a/envelope/main.cpp b/envelope/main.cpp index f0e544e..3889c2a 100644 --- a/envelope/main.cpp +++ b/envelope/main.cpp @@ -52,7 +52,13 @@ void mode_keygen(int keylength){ } void mode_encrypt(const string &pubkeyrepr){ - RSA::Key key(RSA::importKey(pubkeyrepr)); + RSA::Key key; + try { + key=RSA::importKey(pubkeyrepr); + } catch(invalid_argument){ + cerr<<"The given public key is not a valid key!"<<endl; + exit(1); + } string data; char buf[1024]; while(cin){ @@ -65,7 +71,13 @@ void mode_encrypt(const string &pubkeyrepr){ } void mode_decrypt(const string &privkeyrepr){ - RSA::Key key(RSA::importKey(privkeyrepr)); + RSA::Key key; + try { + key=RSA::importKey(privkeyrepr); + } catch(invalid_argument){ + cerr<<"The given private key is not a valid key!"<<endl; + exit(1); + } string data; char buf[1024]; while(cin){ @@ -74,7 +86,12 @@ void mode_decrypt(const string &privkeyrepr){ if(nread==0)continue; data.append(buf,nread); } - cout<<Envelope::decrypt(Base64::decode(data),key)<<flush; + try { + cout<<Envelope::decrypt(Base64::decode(data),key)<<flush; + } catch(invalid_argument){ + cerr<<"Private key doesn't match encrypted text!"<<endl; + exit(1); + } } int main(int argc,char **argv){ |