void main(int argc, char *argv[]){ // checking args and setting params checkargs(argc,argv); // init libgrcypt with secure memory grcrypt_init(); char pass[PASSLENGTH],key[KEYLENGTH_SHA],*file_contents; FILE *fp; size_t input_length; // capturing password for password generation printf("Password: "******"%s", pass); //generating the key get_key(pass,key); if(mode == 0){ // only do this for local mode // for local mode decrypt_file(argv[1],key); printf("successfully decrypted the %s file to %s\n",argv[1],filename); } if(mode == 1){ // printf("Decrypting the %s file to %s\n",encrypted_file,filename); decrypt_file(encrypted_file,key); printf("successfully received and decrypted\n"); remove(encrypted_file); } }
int main() { encrypt_file("sample.txt", "sample.txt.enc", "cppchallenger"); decrypt_file("sample.txt.enc", "sample.txt.dec", "cppchallenger"); encrypt_file("sample.txt", "cppchallenger"); decrypt_file("sample.txt", "cppchallenger"); }
/* * Function: process_file * ---------------------- * Attempt to either encrypt or decrypt the infile using the key and nonce * provided. If there is an error, exit the program. */ void process_file(char *command, char *infile, char *outfile, unsigned char *key, unsigned char *nonce) { size_t r = 0; if (strcmp(command, "encrypt") == 0) { r = encrypt_file(infile, outfile, key, nonce); } else if (strcmp(command, "decrypt") == 0) { r = decrypt_file(infile, outfile, key); } else { usage(); } if (r == 0) { printf("Successfully %sed file %s.\n", command, infile); } else { fprintf(stderr, "Could not %s file %s.\n", command, infile); exit(EXIT_FAILURE); } }
int decrypt_dir(const char *dirName, unsigned char *key) { char buffer[PATH_SIZE]; DIR *dir; struct dirent *entry; dir = opendir(dirName); if (!dir) { perror("diropen"); exit(1); }; while ( (entry = readdir(dir)) != NULL) { if(entry->d_type != DT_DIR && strcmp(entry->d_name,".DS_Store")) { cnct(dirName,entry->d_name,buffer); decrypt_file(dirName,buffer,key); } if(entry->d_type == DT_DIR && strcmp(entry->d_name,"..") && strcmp(entry->d_name,".")) { cnct(dirName,entry->d_name,buffer); decrypt_dir(buffer, key); } } closedir(dir); return 0; }
void decrypt_file( fs::path const & filepath, std::string_view password) { auto temppath = fs::temp_directory_path() / filepath.filename(); decrypt_file(filepath, temppath, password); fs::remove(filepath); fs::rename(temppath, filepath); }
void main(int argc, char* argv[]) { struct block key; FILE *fp1,*fp2; fp1=fopen(argv[1],"rb"); fp2=fopen(argv[3],"wb"); // Converting the key provided as string into key object. key=prepare_key(argv[2]); decrypt_file(fp1,key,fp2); fclose(fp1); fclose(fp2); }
static bool game_data_init(const char *fname, bool from_update) { static bool initialized = false; if(initialized){ return true; } if(!decrypt_file(fname, from_update)){ printf("Error decrypting file!\n"); return false; } xml = mxmlNewXML("1.0"); tree = mxmlLoadString(xml, decoded, MXML_TEXT_CALLBACK); return (tree != NULL); }
int main(int argc,char* argv[]){ int file_size=0; if (argc==1){ cout<< "no file selected !"<<endl; } fstream myfile(reinterpret_cast<const char*>(argv[1]),ios::out | ios::in | ios::trunc); myfile<<"welcome to SGX_Crypt!!!\nThis is a simple test\nfirst encrypt then decrypt of the same file"<<endl; init_Enclave(); ecall_key_iv_generator(global_eid); encrypt_file(reinterpret_cast<const char*>(argv[1])); decrypt_file(reinterpret_cast<const char*>(argv[1])); ecall_cleanup(global_eid); myfile.close(); destroy_Enclave(); return 0; }
//Decrypt the encrypted database pointed by path. //Returns true on success, false on failure. //Path is also written to the lock file. bool db_open(const char *path, const char *passphrase) { if(!db_file_exists(path)) { fprintf(stderr, "%s: does not exists\n", path); return false; } if(!decrypt_file(path, passphrase)) { fprintf(stderr, "Decryption failed\n"); return false; } //Write path as content to our lock file //to determine what db file is open. create_lockfile(path); return true; }
int main(void) { FILE * crypt, *decrypted; int shift; //otwieramy dwa pliki if((crypt = fopen("szyfr_v1.txt", "r")) == NULL) { perror("Blad otwarcia pliku"); exit(1); } decrypted = fopen("deszyfr.txt", "w"); shift = find_shift(crypt); //ustalamy przesuniecie rewind(crypt); //wracamy na poczatek pliku decrypt_file(crypt, ahift, decrypted); //odszyfrowujemy printf("Udanie odszyfrowano i zapisano do pliku!"); fclose(crypt); fclose(decrypted); }
int main(int argc, char *argv[]) { int i; pspDebugScreenInit(); SceUID mod = pspSdkLoadStartModule ("flash0:/kd/chnnlsv.prx",PSP_MEMORY_PARTITION_KERNEL); if (mod < 0) { printf("Error 0x%08X loading/starting chnnlsv.prx.\n", mod); } mod = pspSdkLoadStartModule ("kernelcall.prx",PSP_MEMORY_PARTITION_KERNEL); if (mod < 0) { printf("Error 0x%08X loading/starting kernelcall.prx.\n", mod); } sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); for(;;) { printf("===================================================================="); printf("PPSSPP Save Tool\n"); printf("====================================================================\n\n\n"); switch(currentMenu) { case 0: { int maxOption = 0; for(i = 0; menuList0[i]; i++) { if(i == selectedOption) printf(" > %s\n",menuList0[i]); else printf(" %s\n",menuList0[i]); maxOption++; } int input = ProcessInput(maxOption, &selectedOption); if(input == 0) { currentMenu = 1; selectedOption = 0; } else if(input == 1) { currentMenu = 4; selectedOption = 0; } else if(input == 2) { sceKernelExitGame(); } } break; case 4: case 1: { int maxOption = 0; printf("PPSSPP Decrypted Save Directory : \n"); for(i = 0; menuList1[i]; i++) { if(i == selectedOption) printf(" > %s\n",menuList1[i]); else printf(" %s\n",menuList1[i]); maxOption++; } int input = ProcessInput(maxOption, &selectedOption); if(input == maxOption-1) { if(currentMenu == 1) selectedOption = 0; else selectedOption = 1; currentMenu = 0; } else if(input >= 0) { basePath = selectedOption; if(currentMenu == 1) { currentMenu = 2; UpdateValidDir(1); } else { currentMenu = 5; UpdateValidDir(0); } selectedOption = 0; } } break; case 5: case 2: { int maxOption = 0; if(currentMenu == 2) printf("Save to encrypt : \n"); else printf("Save to decrypt : \n"); if(numDirList == 0) { printf("No compatible data, see README for help on use\n"); } for(i = 0; i < numDirList; i++) { if(i == selectedOption) printf(" > %s\n",dirList[i].name); else printf(" %s\n",dirList[i].name); maxOption++; } for(i = 0; menuList2[i]; i++) { if((i+numDirList) == selectedOption) printf(" > %s\n",menuList2[i]); else printf(" %s\n",menuList2[i]); maxOption++; } printf("\n Invalid path : \n"); for(i = 0; i < numInvalidDirList && i < (22-numDirList); i++) { switch(invalidDirList[i].errorId) { case 1: printf(" %s : ENCRYPT_INFO.BIN not found\n",invalidDirList[i].name); break; case 2: printf(" %s : ENCRYPT_INFO.BIN read error\n",invalidDirList[i].name); break; case 3: printf(" %s : ENCRYPT_INFO.BIN wrong version\n",invalidDirList[i].name); break; case 4: printf(" %s : PARAM.SFO not found\n",invalidDirList[i].name); break; case 5: printf(" %s : PARAM.SFO read error\n",invalidDirList[i].name); break; case 6: printf(" %s : SAVEDATA_FILE_LIST not found in PARAM.SFO\n",invalidDirList[i].name); break; case 7: printf(" %s : no save name in SAVEDATA_FILE_LIST\n",invalidDirList[i].name); break; case 8: printf(" %s : no save found\n",invalidDirList[i].name); break; default: break; } } int input = ProcessInput(maxOption, &selectedOption); if(input == numDirList) { if(currentMenu == 2) currentMenu = 1; else currentMenu = 4; selectedOption = basePath; } else if(input >= 0) { if(currentMenu == 2) currentMenu = 3; else currentMenu = 6; workDir = input; selectedOption = 0; } } break; case 6: case 3: { EncryptFileInfo encryptInfo; if(FileRead(menuList1[basePath], dirList[workDir].name, "ENCRYPT_INFO.BIN",(u8*)&encryptInfo,sizeof(encryptInfo)) < 0) { printf("Can't read encrypt file\n"); } else { printf("Key : "); for(i = 0; i < 16; i++) printf(" %02x",(u8)encryptInfo.key[i]); printf("\n"); printf("SDK Version : 0x%x\n",encryptInfo.sdkVersion); char srcPath[128]; char dstPath[128]; if(currentMenu == 3) { sprintf(srcPath,"%s%s",menuList1[basePath], dirList[workDir].name); sprintf(dstPath,"ms0:/PSP/SAVEDATA/%s",dirList[workDir].name); sceIoMkdir(dstPath,0777); } else { sprintf(srcPath,"ms0:/PSP/SAVEDATA/%s",dirList[workDir].name); sprintf(dstPath,"%s%s",menuList1[basePath], dirList[workDir].name); } int dfd; dfd = sceIoDopen(srcPath); if(dfd >= 0) { SceIoDirent dirinfo; while(sceIoDread(dfd, &dirinfo) > 0) { if(!(dirinfo.d_stat.st_mode & 0x2000)) // is not a file continue; if(strcmp(dirinfo.d_name,"ENCRYPT_INFO.BIN") == 0) // don't copy encrypt info continue; FileCopy(srcPath, dstPath, dirinfo.d_name); } sceIoDclose(dfd); } if(currentMenu == 3) { char decryptedFile[258], encryptedFile[258], srcSFO[258], dstSFO[258]; sprintf(decryptedFile,"%s/%s",srcPath ,dirList[workDir].saveFile); sprintf(srcSFO,"%s/PARAM.SFO",srcPath); sprintf(encryptedFile,"%s/%s",dstPath ,dirList[workDir].saveFile); sprintf(dstSFO,"%s/PARAM.SFO",dstPath); printf("Encoding %s into %s\n",decryptedFile, encryptedFile); int ret = encrypt_file(decryptedFile, encryptedFile, dirList[workDir].saveFile, srcSFO, dstSFO, encryptInfo.key[0] != 0 ? encryptInfo.key : NULL, GetSDKMainVersion(encryptInfo.sdkVersion) ); if(ret < 0) { printf("Error: encrypt_file() returned %d\n\n", ret); } else { printf("Successfully wrote %d bytes to\n", ret); printf(" %s\n", encryptedFile); printf("and updated hashes in\n"); printf(" %s\n\n", dstSFO); } } else { char decryptedFile[258], encryptedFile[258]; sprintf(encryptedFile,"%s/%s",srcPath ,dirList[workDir].saveFile); sprintf(decryptedFile,"%s/%s",dstPath ,dirList[workDir].saveFile); printf("Decoding %s into %s\n",encryptedFile, decryptedFile); int ret = decrypt_file(decryptedFile, encryptedFile, encryptInfo.key[0] != 0 ? encryptInfo.key : NULL, GetSDKMainVersion(encryptInfo.sdkVersion)); if(ret < 0) { printf("Error: decrypt_file() returned %d\n\n", ret); } else { printf("Successfully wrote %d bytes to\n", ret); printf(" %s\n", decryptedFile); } } printf(" > Back\n"); int input = ProcessInput(1, &selectedOption); if(input >= 0) { if(currentMenu == 3) currentMenu = 2; else currentMenu = 5; selectedOption = 0; } } } break; default: sceKernelExitGame(); break; } pspDebugScreenClear(); sceDisplayWaitVblankStart(); sceGuSwapBuffers(); } return 0; }
int main(int argc, char **argv) { xmlSecKeysMngrPtr mngr; #ifndef XMLSEC_NO_XSLT xsltSecurityPrefsPtr xsltSecPrefs = NULL; #endif /* XMLSEC_NO_XSLT */ assert(argv); if(argc != 3) { fprintf(stderr, "Error: wrong number of arguments.\n"); fprintf(stderr, "Usage: %s <enc-file> <key-file1> [<key-file2> [...]]\n", argv[0]); return(1); } /* Init libxml and libxslt libraries */ xmlInitParser(); LIBXML_TEST_VERSION xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS; xmlSubstituteEntitiesDefault(1); #ifndef XMLSEC_NO_XSLT xmlIndentTreeOutput = 1; #endif /* XMLSEC_NO_XSLT */ /* Init libxslt */ #ifndef XMLSEC_NO_XSLT /* disable everything */ xsltSecPrefs = xsltNewSecurityPrefs(); xsltSetSecurityPrefs(xsltSecPrefs, XSLT_SECPREF_READ_FILE, xsltSecurityForbid); xsltSetSecurityPrefs(xsltSecPrefs, XSLT_SECPREF_WRITE_FILE, xsltSecurityForbid); xsltSetSecurityPrefs(xsltSecPrefs, XSLT_SECPREF_CREATE_DIRECTORY, xsltSecurityForbid); xsltSetSecurityPrefs(xsltSecPrefs, XSLT_SECPREF_READ_NETWORK, xsltSecurityForbid); xsltSetSecurityPrefs(xsltSecPrefs, XSLT_SECPREF_WRITE_NETWORK, xsltSecurityForbid); xsltSetDefaultSecurityPrefs(xsltSecPrefs); #endif /* XMLSEC_NO_XSLT */ /* Init xmlsec library */ if(xmlSecInit() < 0) { fprintf(stderr, "Error: xmlsec initialization failed.\n"); return(-1); } /* Check loaded library version */ if(xmlSecCheckVersion() != 1) { fprintf(stderr, "Error: loaded xmlsec library version is not compatible.\n"); return(-1); } /* Load default crypto engine if we are supporting dynamic * loading for xmlsec-crypto libraries. Use the crypto library * name ("openssl", "nss", etc.) to load corresponding * xmlsec-crypto library. */ #ifdef XMLSEC_CRYPTO_DYNAMIC_LOADING if(xmlSecCryptoDLLoadLibrary(BAD_CAST XMLSEC_CRYPTO) < 0) { fprintf(stderr, "Error: unable to load default xmlsec-crypto library. Make sure\n" "that you have it installed and check shared libraries path\n" "(LD_LIBRARY_PATH) envornment variable.\n"); return(-1); } #endif /* XMLSEC_CRYPTO_DYNAMIC_LOADING */ /* Init crypto library */ if(xmlSecCryptoAppInit(NULL) < 0) { fprintf(stderr, "Error: crypto initialization failed.\n"); return(-1); } /* Init xmlsec-crypto library */ if(xmlSecCryptoInit() < 0) { fprintf(stderr, "Error: xmlsec-crypto initialization failed.\n"); return(-1); } /* create keys manager and load keys */ mngr = load_des_keys(&(argv[2]), argc - 2); if(mngr == NULL) { return(-1); } if(decrypt_file(mngr, argv[1]) < 0) { xmlSecKeysMngrDestroy(mngr); return(-1); } /* destroy keys manager */ xmlSecKeysMngrDestroy(mngr); /* Shutdown xmlsec-crypto library */ xmlSecCryptoShutdown(); /* Shutdown crypto library */ xmlSecCryptoAppShutdown(); /* Shutdown xmlsec library */ xmlSecShutdown(); /* Shutdown libxslt/libxml */ #ifndef XMLSEC_NO_XSLT xsltFreeSecurityPrefs(xsltSecPrefs); xsltCleanupGlobals(); #endif /* XMLSEC_NO_XSLT */ xmlCleanupParser(); return(0); }
int main(int argc, char *argv[]) { int res = EXIT_FAILURE; int err; progname = basename(argv[0]); while ( 1 ) { int c; c = getopt(argc, argv, "adi:m:o:hp:v:k:r:s:"); if (c == -1) break; switch (c) { case 'd': do_decrypt = 1; break; case 'i': ifname = optarg; break; case 'l': longstate = 1; break; case 'm': magic = optarg; break; case 'o': ofname = optarg; break; case 'p': product = optarg; break; case 'v': version = optarg; break; case 'k': crypt_key = optarg; break; case 's': seed = strtoul(optarg, NULL, 16); break; case 'h': usage(EXIT_SUCCESS); break; default: usage(EXIT_FAILURE); break; } } err = check_params(); if (err) goto out; if (do_decrypt) err = decrypt_file(); else err = encrypt_file(); if (err) goto out; res = EXIT_SUCCESS; out: return res; }
int main(int argc, char **argv) { xmlSecKeysMngrPtr mngr; assert(argv); if(argc != 2) { printf_a_ignorar3(stderr, "Error: wrong number of arguments.\n"); printf_a_ignorar3(stderr, "Usage: %s <enc-file>\n", argv[0]); return(1); } /* Init libxml and libxslt libraries */ xmlInitParser(); LIBXML_TEST_VERSION xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS; xmlSubstituteEntitiesDefault(1); #ifndef XMLSEC_NO_XSLT xmlIndentTreeOutput = 1; #endif /* XMLSEC_NO_XSLT */ /* Init xmlsec library */ if(xmlSecInit() < 0) { printf_a_ignorar3(stderr, "Error: xmlsec initialization failed.\n"); return(-1); } /* Check loaded library version */ if(xmlSecCheckVersion() != 1) { printf_a_ignorar3(stderr, "Error: loaded xmlsec library version is not compatible.\n"); return(-1); } /* Load default crypto engine if we are supporting dynamic * loading for xmlsec-crypto libraries. Use the crypto library * name ("openssl", "nss", etc.) to load corresponding * xmlsec-crypto library. */ #ifdef XMLSEC_CRYPTO_DYNAMIC_LOADING if(xmlSecCryptoDLLoadLibrary(BAD_CAST XMLSEC_CRYPTO) < 0) { printf_a_ignorar3(stderr, "Error: unable to load default xmlsec-crypto library. Make sure\n" "that you have it installed and check shared libraries path\n" "(LD_LIBRARY_PATH) envornment variable.\n"); return(-1); } #endif /* XMLSEC_CRYPTO_DYNAMIC_LOADING */ /* Init crypto library */ if(xmlSecCryptoAppInit(NULL) < 0) { printf_a_ignorar3(stderr, "Error: crypto initialization failed.\n"); return(-1); } /* Init xmlsec-crypto library */ if(xmlSecCryptoInit() < 0) { printf_a_ignorar3(stderr, "Error: xmlsec-crypto initialization failed.\n"); return(-1); } /* create keys manager and load keys */ mngr = create_files_keys_mngr(); if(mngr == NULL) { return(-1); } if(decrypt_file(mngr, argv[1]) < 0) { xmlSecKeysMngrDestroy(mngr); return(-1); } /* destroy keys manager */ xmlSecKeysMngrDestroy(mngr); /* Shutdown xmlsec-crypto library */ xmlSecCryptoShutdown(); /* Shutdown crypto library */ xmlSecCryptoAppShutdown(); /* Shutdown xmlsec library */ xmlSecShutdown(); /* Shutdown libxslt/libxml */ #ifndef XMLSEC_NO_XSLT xsltCleanupGlobals(); #endif /* XMLSEC_NO_XSLT */ xmlCleanupParser(); return(0); }
int main(int argc, char *argv[]) { timer t; t.set_print_mode(HMS_MODE); bencrypt=false; bdecrypt=false; bgen_pk=false; bfind_point=false; btest_point=false; bwipe_file=false; bhelp=false; bfile=false; buser=false; bversion=false; bks=false; for(int i=1;i<argc;i++) { if((strcmp(argv[i],"-e")==0) || (strcmp(argv[i],"--encrypt")==0)) { if (i+1 < argc) if(!is_option(argv[i+1])) { bencrypt=true; filename=argv[i+1]; bfile=true; i++; continue; } banner(); cerr<<"\nAZTECC ERROR : No filename given."<<endl; exit(1); } if((strcmp(argv[i],"-d")==0) || (strcmp(argv[i],"--decrypt")==0)) { if (i+1 < argc) if(!is_option(argv[i+1])) { bdecrypt=true; filename=argv[i+1]; bfile=true; i++; continue; } banner(); cerr<<"\nAZTECC ERROR : No filename given."<<endl; exit(1); } if((strcmp(argv[i],"-g")==0) || (strcmp(argv[i],"--genkey")==0)) bgen_pk=true; if((strcmp(argv[i],"-k")==0) || (strcmp(argv[i],"--keysize")==0)) { if (i+1 < argc) if(!is_option(argv[i+1])) { bks=true; keysize=argv[i+1]; i++; continue; } banner(); cerr<<"\nAZTECC ERROR : No valid keysize given."<<endl; exit(1); } if((strcmp(argv[i],"-u")==0) || (strcmp(argv[i],"--user")==0)) { if (i+1 < argc) if(!is_option(argv[i+1])) { username=argv[i+1]; buser=true; i++; continue; } banner(); cerr<<"\nAZTECC ERROR : No valid username given."<<endl; exit(1); } if((strcmp(argv[i],"-pk")==0) || (strcmp(argv[i],"--pubkey")==0)) { if(!is_option(argv[i+1])) { pubkey=argv[i+1]; i++; continue; } banner(); cerr<<"\nAZTECC ERROR : No public key filename given."<<endl; exit(1); } // find and test point if((strcmp(argv[i],"-f")==0) || (strcmp(argv[i],"--find")==0)) bfind_point=true; if((strcmp(argv[i],"-t")==0) || (strcmp(argv[i],"--test")==0)) btest_point=true; if((strcmp(argv[i],"-h")==0) || (strcmp(argv[i],"--help")==0)) bhelp=true; if((strcmp(argv[i],"-v")==0) || (strcmp(argv[i],"--version")==0)) bversion=true; if((strcmp(argv[i],"-w")==0) || (strcmp(argv[i],"--wipe")==0)) { if (i+1 < argc) if(!is_option(argv[i+1])) { filename=argv[i+1]; bwipe_file=true; bfile=true; i++; continue; } banner(); cerr<<"\nAZTECC ERROR : No filename given."<<endl; exit(1); } } if((bencrypt) && (buser) && (bfile) && (!bdecrypt) && (!bgen_pk) && (!bfind_point) && (!btest_point) && (!bhelp) && (!bwipe_file) && (!bversion) && (!bks)) { t.start_timer(); encrypt_file(pubkey,username,filename); t.stop_timer(); cout<<"\nElapsed time : "<<t<<endl; exit(0); } if((bdecrypt) && (bfile) && (!buser) && (!bencrypt) && (!bgen_pk) && (!bfind_point) && (!btest_point) && (!bhelp) && (!bwipe_file) && (!bversion) && (!bks)) { t.start_timer(); decrypt_file(pubkey,filename); t.stop_timer(); cout<<"\nElapsed time : "<<t<<endl; exit(0); } if((bgen_pk) && (bks) && (!buser) && (!bencrypt) && (!bdecrypt) && (!bfind_point) && (!btest_point) && (!bhelp) && (!bwipe_file) && (!bversion)) { if(strcmp(keysize,"160")==0) blocksize=20; else if(strcmp(keysize,"192")==0) blocksize=24; else { banner(); cerr<<"\nAZTECC ERROR : Keysize not valid.\n"; exit(1); } gen_pubkey(pubkey,blocksize); exit(0); } if((bfind_point) && (!bencrypt) && (!bdecrypt) && (!bgen_pk) && (!btest_point) && (!bhelp) && (!bwipe_file) && (!bversion) && (!buser) && (!bks)) { find_point(); exit(0); } if((btest_point) && (!bencrypt) && (!bdecrypt) && (!bgen_pk) && (!bfind_point) && (!bhelp) && (!bwipe_file) && (!bversion) && (!buser) && (!bks)) { test_point(); exit(0); } if((bwipe_file) && (bfile) && (!bencrypt) && (!bdecrypt) && (!bgen_pk) && (!bfind_point) && (!btest_point) && (!bhelp) && (!bversion) && (!buser) && (!bks)) { wipe_file(filename); exit(0); } if((bversion) && (!bencrypt) && (!bdecrypt) && (!bgen_pk) && (!bfind_point) && (!btest_point) && (!bhelp) && (!bwipe_file) && (!buser) && (!bks)) { version(); exit(0); } if(bhelp) { usage(); exit(0); } else usage(); return 0; }
int main(int argc, char* argv[]){ if(argc != 4){ printf("ERROR: Missing command line arguments\nUsage: ./efsmanager master_password user_password_file date_and_time_of_last_change\n"); return 1 ; } printf("Found master password: %s\n",argv[1]); printf("Found user password file: %s\n",argv[2]); printf("Found date of last change: %s\n",argv[3]); printf("Found master_iv: %s\n",master_iv); //copy argv[2] to password_file /* use the master password and master IV to generate the master encryption decryption key and master hmace key. Store the master encryption decryption key in master_encdec_key and store the master hmac key in master_hmac_key */ unsigned char command[1024]; int operation_status ; while(1){ printf("Available commands:\n(1) create_file\n(2) delete_file\n(3) encrypt_file\n(4) decrypt_file\n(5) read_from_file\n(6) write_to_file\n(7) file_size\n(8) file_integrity_check\n(9) system_health_check\n(10) quit\n\n\n"); printf("enter a command: "); scanf("%s",command) ; // printf("\n") ; operation_status = OKAY ; if(!strcmp(command,"create_file")){ printf("username: "******"%s",username) ; printf("password: "******"%s",password) ; printf("file name: "); unsigned char pFile[1024] ; scanf("%s",pFile); operation_status = create_file(username,password,pFile) ; } else if(!strcmp(command,"delete_file")){ printf("username: "******"%s",username) ; printf("password: "******"%s",password) ; printf("file name: "); unsigned char pFile[1024] ; scanf("%s",pFile); operation_status = delete_file(username,password,pFile) ; } else if(!strcmp(command,"encrypt_file")){ printf("username: "******"%s",username) ; printf("password: "******"%s",password) ; printf("file name to encrypt: "); unsigned char pFile[1024] ; scanf("%s",pFile); operation_status = encrypt_file(username,password,pFile) ; } else if(!strcmp(command,"decrypt_file")){ printf("username: "******"%s",username) ; printf("password: "******"%s",password) ; printf("file name to decrypt: "); unsigned char pFile[1024] ; scanf("%s",pFile); operation_status = decrypt_file(username,password,pFile) ; } else if(!strcmp(command,"file_size")){ printf("username: "******"%s",username) ; printf("password: "******"%s",password) ; printf("file name: "); unsigned char pFile[1024] ; scanf("%s",pFile); operation_status = file_size(username,password,pFile) ; } else if(!strcmp(command,"file_integrity_check")){ printf("username: "******"%s",username) ; printf("password: "******"%s",password) ; printf("file name: "); unsigned char pFile[1024] ; scanf("%s",pFile); operation_status = file_integrity_check(username,password,pFile) ; } else if(!strcmp(command,"system_health_check")){ operation_status = system_health_check(); } else if(!strcmp(command,"read_from_file")){ printf("username: "******"%s",username) ; printf("password: "******"%s",password) ; printf("file name: "); unsigned char pFile[1024] ; scanf("%s",pFile); printf("position to read from: "); int offset ; scanf("%d",&offset); printf("how many characters to read: "); int len; scanf("%d",&len); unsigned char *content = read_from_file(username,password,pFile,offset,len) ; if(content == NULL){ printf("ERROR: Reading from file\n"); continue; } else{ printf("CONTENT:\n%s\n",content); } } else if(!strcmp(command,"write_to_file")){ printf("username: "******"%s",username) ; printf("password: "******"%s",password) ; printf("file name: "); unsigned char pFile[1024] ; scanf("%s",pFile); printf("position to write to: "); int offset ; scanf("%d",&offset); printf("Content to write:\n "); char content[8192] ; int i = 0 ; while(1){ char ch = getchar(); if(ch == EOF) break ; content[i] = ch ; ++i ; } operation_status = write_to_file(username,password,pFile,offset,content) ; } else if(!strcmp(command,"quit")){ printf("INFO: Got the quit command\n"); printf("Program terminating\n"); break; } else{ printf("ERROR: Unknown command %s\n",command); printf("INFO: Ignoring command\n") ; } if(operation_status == ERROR) printf("Operation %s failed\n",command) ; } return 0; }
int main(int argc, char *argv[]) { if(argc < 5){ fprintf(stderr, "Usage:\n./scss </path/to/plaintext> </path/to/output-encrypted> <encrypt/decrypt> <mode>\n./scss </path/to/encrypted> </path/to/output-decrypted> <encrypt/decrypt> <mode>\nValid Modes: [ecb, cbc, ofb, cfb]\n"); return -1; } const char *inputFile = argv[1], *outputFile = argv[2], *operation = argv[3], *mode = argv[4]; if(strcmp(operation, "encrypt") != 0 && strcmp(operation, "decrypt") != 0) { fprintf(stderr, "Invalid Operation. Valid Modes: [encrypt, decrypt]\n"); return -2; } int dOperation = 0; if(strcmp(operation, "decrypt") == 0) dOperation = 1; if(strcmp(mode, "ecb") != 0 && strcmp(mode, "cbc") != 0 && strcmp(mode, "ofb") != 0 && strcmp(mode, "cfb") != 0) { fprintf(stderr, "Invalid Mode. Valid Modes: [ecb, cbc, ofb, cfb]\n"); return -3; } int dMode = 0; //default ecb if(strcmp(mode, "cbc") == 0){ dMode = 1; } else if(strcmp(mode, "ofb") == 0){ dMode = 2; } else if(strcmp(mode, "cfb") == 0){ dMode = 3; } struct lfsr l_17, l_25; int num_bits_1 = 17, num_bits_2 = 25; int taps_1[17] = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, //x^17 + x^2 + 1 taps_2[25] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1 }; //x^25 + x^21 + x^20 + x^10 + 1 setup_lfsr(&l_17, &num_bits_1, taps_1); setup_lfsr(&l_25, &num_bits_2, taps_2); //Some random 40-bit Key BYTE key[40] = { 1,0,0,0,0,0,0,1,0,0, 1,0,0,0,0,1,0,0,0,0, 1,0,0,0,0,0,0,1,0,0, 1,0,0,0,0,0,0,1,0,0 }; //some i.v. unsigned char initialization_vector = 0xa2; struct lfsr *init_arr[2] = { &l_17, &l_25 }; init_with_key(init_arr, 2, key); if(dOperation == 0) encrypt_file(inputFile, &l_17, &l_25, outputFile, &dMode, initialization_vector); else decrypt_file(inputFile, &l_17, &l_25, outputFile, &dMode, initialization_vector); return 0; }
int main(int argc, char **argv) { // mostly "counting" variables... int c; int i; int err; int skip; int *csize; char * fname; unsigned char * key; unsigned char * cipher_text; size_t keysize = 16; unsigned int port; // Parse the cmd line options // This should have been done // using getopt, but I never // had the chance to fix it! c = strlen(argv[1]); fname = (char *) malloc(c*sizeof(char)); strncpy(fname,argv[1],c); csize = (int *) malloc(sizeof(int)); if ((argc == 3) && (strcmp(argv[2],"-l")==0)) { /* Stand alone mode first */ int in_len = strlen(fname); char ofname[in_len+6]; char tfname[in_len+6]; for(i=0;i< c;++i) { if(fname[i] == '.') { skip = c - i; break; } } strncpy(tfname,fname,in_len); tfname[in_len-skip] = '\0'; sprintf(ofname,"%s.check",tfname); // Check for filename conflict if (access(ofname,F_OK)!=-1) { printf("Output File Exists!\n"); return 33; } /* Get the key and setyp up libgcrypt */ key = (unsigned char *) load_crypto(keysize); /* This handles the decryption */ decrypt_file(fname,ofname,key,keysize); } else if ((argc == 4) && (strcmp(argv[2],"-d")==0)) { /* Daemon mode */ // Check for filename conflict if (access(fname,F_OK)!=-1) { printf("Output File Exists!\n"); return 33; } port = atoi(argv[3]); // Get the cipher text from the network cipher_text = start_server(port,csize); // Get the key from the password key = (unsigned char *) load_crypto(keysize); // Decrypt the file err = decrypt_network_file(fname, key, keysize, cipher_text,*csize); return err; } else { /* Usage.... */ printf("\nUsage: \n" " techdec <filename> [-d <Port>] [-l]\n\n"); return 1; } return 0; }