fork download
  1. #include<sys/types.h>
  2. #include<sys/stat.h>
  3. #include<fstream>
  4. #include<sstream>
  5. #include<iostream>
  6. #include<string>
  7. #include<cstring>
  8. #include<stdio.h>
  9. #include<stdlib.h>
  10. using namespace std;
  11. int main ( int argc, char *argv[] ){
  12. string a=argv[1];
  13. string op=argv[2];
  14. string key=argv[3];
  15. string file1=argv[4];
  16. string file2;
  17. string file_name;
  18. string sys;
  19. string filev;
  20. string files;
  21. string new_file_name;
  22. string new_file_name2;
  23. int pos = file1.find(".");
  24. file_name = file1.substr(0, pos);
  25. if(a=="1"){
  26. if(op=="e"){
  27. sys="openssl rsautl -encrypt -inkey "+ key +" -pubin -in " + file1+" -out "+file_name+".enc";
  28. system(sys.c_str());
  29. }
  30. else if(op=="d")
  31. {
  32. sys="openssl rsautl -decrypt -inkey " + key + " -in " + file1+" -out "+file_name+".dec";
  33. system(sys.c_str());
  34. }
  35. }
  36. else if(a=="2")
  37. {
  38. if(op=="s"){
  39. sys = "openssl dgst -sha512 -r -out " + file_name+".sha512 "+file1;
  40. system(sys.c_str());
  41. sys = "openssl rsautl -inkey " +key+" -sign -in "+ file_name+".sha512 -out "+file_name+".sign";
  42. system(sys.c_str());
  43. }
  44. else if(op=="v"){
  45. sys = "openssl dgst -sha512 -r -out " + file_name+".sha512 "+file1;
  46. system(sys.c_str());
  47. filev=new_file_name+".sha512";
  48. sys = "openssl rsautl -inkey " + key + " -pubin -verify -in " + file2 + " -out " + file_name+".verify";
  49. system(sys.c_str());
  50. files=new_file_name2+".verify";
  51.  
  52. string namefile1=file_name+".sh512";
  53. string namefile2=file_name+".verify";
  54. string new_content1;
  55. string new_content2;
  56. int result;
  57. stringstream strStream1;
  58. stringstream strStream2;
  59. ifstream inFile1;
  60. ifstream inFile2;
  61. strStream1 << inFile1.rdbuf();
  62. string str1 = strStream1.str();
  63. strStream2 << inFile2.rdbuf();
  64. string str2 = strStream2.str();
  65.  
  66. inFile1.open(namefile1.c_str());
  67. inFile2.open(namefile2.c_str());
  68. int pos = str1.find("(");
  69. new_content1 = str1.substr(0, pos);
  70. int poss = str2.find("(");
  71. new_content2 = str2.substr(0, poss);
  72.  
  73.  
  74. if (new_content1.compare(new_content2) != 0){cout <<"verification failed"<<endl; }
  75. else {cout <<" verification succeeded"<<endl; }
  76. }
  77. }
  78. }
  79.  
  80.  
  81.  
Runtime error #stdin #stdout #stderr 0s 4292KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_M_construct null not valid