/****************************************************************** * Function: FileInterface * * This function gives the user the option of either Encrypting or * decrypting whichever file they enter. * *Inputs: None *Output: None ******************************************************************/ void FileInterface() { char *choice; choice = (char *) malloc(CHOICESIZE * sizeof(char)) ; if(choice == NULL) { fprintf(stderr, "Out of memory - getting space for choice\n"); exit (-2); } PrintSMenu(); fscanf(stdin, "%s", choice); switch(choice[0]) { case 'E': TranslateFile(); break; case 'e': TranslateFile(); break; case'D': DecryptFile(); break; case 'd': DecryptFile(); break; default: return; break; } free(choice); return; }
BOOL CEncryptFile::DecryptDir(CString strKey, CString strSrcDir, CString strDstDir, CProgressCtrl *pCtal) { //AfxMessageBox("创建文件夹"+target); CFileFind finder; CString stPath; BOOL re = FALSE; stPath.Format(_T("%s/*.*"), strSrcDir); BOOL bWorking = finder.FindFile(stPath); while (bWorking) { bWorking = finder.FindNextFile(); if (finder.IsDirectory() && !finder.IsDots())//是文件夹 而且 名称不含 . 或 .. { //递归解密+"/"+finder.GetFileName() DecryptDir(strKey, finder.GetFilePath(), strDstDir + _T("\\") + finder.GetFileName(), pCtal); } else//是文件 则直接解密 { CString stSrcFile = finder.GetFilePath(); BOOL result = (GetFileAttributes(stSrcFile) & FILE_ATTRIBUTE_DIRECTORY); if (!result) { re = DecryptFile(strKey, finder.GetFilePath(), strDstDir + _T("\\") + finder.GetFileName()); pCtal->StepIt(); } } } return TRUE; }
// // FUNCTION: CDrmShlExt::OnDecrypt(HWND) // // PURPOSE: OnDecrypt handles the "Decrypt" verb of the shell extension. // void CDrmShlExt::OnDecrypt(HWND hWnd) { /*TCHAR szMessage[300]; _stprintf_s(szMessage, 300, _T("The following files were successful decrypted:\n\n%s"), m_szFileName); MessageBox(hWnd, szMessage, _T("Rights Network File Decrypter"), MB_ICONINFORMATION); */ //DWORD dwLastErr; std::wstring msg = L"The following files were successful decrypted :\n"; string_list::iterator i; for(i=this->fileList.begin(); i!=this->fileList.end(); i++){ //msg += (*i) + _T("\n"); char *encFile = (char*)(*i).c_str(); std::wstring decFile = (*i).substr(0, (*i).length() - 4) + L"\n"; //std::wstring passkey = L"N67C9PpD,uqZRG(MxeQWzCdmzqezJGo8tnMk[4s(FpHkdWtY.t"; std::wstring passkey = L"nothing"; const char* keyStr = "nothing"; DecryptFile(encFile, (char*)decFile.c_str(), keyStr); //dwLastErr = GetLastError(); msg += decFile + L"\n"; } MessageBox(0, msg.c_str(), _T("Rights Network File Decrypter"), 0); }
static int encfs_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { int res; (void) fi; char *key = DJ_DATA->encfs_keyphrase; char fpath[PATH_MAX]; // Full buffer to pass to static function dj_fullpath(fpath, path); bool is_encrypted = IsEncrypted(fpath); if (key == NULL) printf("\n\n **** KEY IS NULL **** \n\n"); printf("\n\n***** FILE ENCRYPTED: %d *****\n\n", is_encrypted); if(is_encrypted) { char tpath[PATH_MAX]; tmpFileName(fpath, tpath); //int td = open(tpath, O_WRONLY); FILE* realFile = fopen(fpath, "rb"); FILE* tmpFile = fopen(tpath, "wb"); DecryptFile(realFile, tmpFile, key); //fflush(tmpFile); //actual_descriptor = dup(fileno(tmpFile)); fclose(realFile); fclose(tmpFile); int fd = open(tpath, O_RDONLY); res = pread(fd, buf, size, offset); close(fd); } else { int rd = open(fpath, O_RDONLY); if (rd == -1) return -errno; res = pread(rd, buf, size, offset); if (res == -1) res = -errno; close(rd); } return res; }
int main(int argc, char *argv[]) #endif { #ifdef _CRTDBG_LEAK_CHECK_DF // Turn on leak-checking int tempflag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ); tempflag |= _CRTDBG_LEAK_CHECK_DF; _CrtSetDbgFlag( tempflag ); #endif #if defined(__MWERKS__) && defined(macintosh) argc = ccommand(&argv); #endif try { std::string command, executableName, edcFilename; if (argc < 2) command = 'h'; else command = argv[1]; if (FIPS_140_2_ComplianceEnabled()) { edcFilename = "edc.dat"; #ifdef CRYPTOPP_WIN32_AVAILABLE TCHAR filename[MAX_PATH]; GetModuleFileName(GetModuleHandle(NULL), filename, sizeof(filename)); executableName = filename; std::string::size_type pos = executableName.rfind('\\'); if (pos != std::string::npos) edcFilename = executableName.substr(0, pos+1) + edcFilename; #else executableName = argv[0]; #endif if (command.substr(0, 4) != "fips") { byte expectedModuleDigest[SHA1::DIGESTSIZE]; FileSource(edcFilename.c_str(), true, new HexDecoder(new ArraySink(expectedModuleDigest, sizeof(expectedModuleDigest)))); DoPowerUpSelfTest(executableName.c_str(), expectedModuleDigest); } } switch (command[0]) { case 'g': { char seed[1024], privFilename[128], pubFilename[128]; unsigned int keyLength; cout << "Key length in bits: "; cin >> keyLength; cout << "\nSave private key to file: "; cin >> privFilename; cout << "\nSave public key to file: "; cin >> pubFilename; cout << "\nRandom Seed: "; ws(cin); cin.getline(seed, 1024); GenerateRSAKey(keyLength, privFilename, pubFilename, seed); return 0; } case 'r': { switch (argv[1][1]) { case 's': RSASignFile(argv[2], argv[3], argv[4]); return 0; case 'v': { bool verified = RSAVerifyFile(argv[2], argv[3], argv[4]); cout << (verified ? "valid signature" : "invalid signature") << endl; return 0; } default: { char privFilename[128], pubFilename[128]; char seed[1024], message[1024]; cout << "Private key file: "; cin >> privFilename; cout << "\nPublic key file: "; cin >> pubFilename; cout << "\nRandom Seed: "; ws(cin); cin.getline(seed, 1024); cout << "\nMessage: "; cin.getline(message, 1024); string ciphertext = RSAEncryptString(pubFilename, seed, message); cout << "\nCiphertext: " << ciphertext << endl; string decrypted = RSADecryptString(privFilename, ciphertext.c_str()); cout << "\nDecrypted: " << decrypted << endl; return 0; } } } case 'm': DigestFile(argv[2]); return 0; case 't': { if (command == "tv") { return !RunTestDataFile(argv[2]); } // VC60 workaround: use char array instead of std::string to workaround MSVC's getline bug char passPhrase[MAX_PHRASE_LENGTH], plaintext[1024]; cout << "Passphrase: "; cin.getline(passPhrase, MAX_PHRASE_LENGTH); cout << "\nPlaintext: "; cin.getline(plaintext, 1024); string ciphertext = EncryptString(plaintext, passPhrase); cout << "\nCiphertext: " << ciphertext << endl; string decrypted = DecryptString(ciphertext.c_str(), passPhrase); cout << "\nDecrypted: " << decrypted << endl; return 0; } case 'e': case 'd': if (command == "e64") Base64Encode(argv[2], argv[3]); else if (command == "d64") Base64Decode(argv[2], argv[3]); else if (command == "e16") HexEncode(argv[2], argv[3]); else if (command == "d16") HexDecode(argv[2], argv[3]); else { char passPhrase[MAX_PHRASE_LENGTH]; cout << "Passphrase: "; cin.getline(passPhrase, MAX_PHRASE_LENGTH); if (command == "e") EncryptFile(argv[2], argv[3], passPhrase); else DecryptFile(argv[2], argv[3], passPhrase); } return 0; case 's': if (argv[1][1] == 's') { char seed[1024]; cout << "\nRandom Seed: "; ws(cin); cin.getline(seed, 1024); SecretShareFile(atoi(argv[2]), atoi(argv[3]), argv[4], seed); } else SecretRecoverFile(argc-3, argv[2], argv+3); return 0; case 'i': if (argv[1][1] == 'd') InformationDisperseFile(atoi(argv[2]), atoi(argv[3]), argv[4]); else InformationRecoverFile(argc-3, argv[2], argv+3); return 0; case 'v': return !Validate(argc>2 ? atoi(argv[2]) : 0, argv[1][1] == 'v', argc>3 ? argv[3] : NULL); case 'b': if (argc<3) BenchMarkAll(); else BenchMarkAll((float)atof(argv[2])); return 0; case 'z': GzipFile(argv[3], argv[4], argv[2][0]-'0'); return 0; case 'u': GunzipFile(argv[2], argv[3]); return 0; case 'f': if (command == "fips") FIPS140_SampleApplication(executableName.c_str(), edcFilename.c_str()); else if (command == "fips-rand") FIPS140_GenerateRandomFiles(); else if (command == "ft") ForwardTcpPort(argv[2], argv[3], argv[4]); return 0; case 'a': if (AdhocTest) return (*AdhocTest)(argc, argv); else return 0; default: FileSource usage("usage.dat", true, new FileSink(cout)); return 1; } } catch(CryptoPP::Exception &e) { cout << "\nCryptoPP::Exception caught: " << e.what() << endl; return -1; } catch(std::exception &e) { cout << "\nstd::exception caught: " << e.what() << endl; return -2; } }
void vmsFDMCustomizations::Load(HANDLE hFile) { Free (); vmsMemFile file; DWORD dw; file.Use (hFile, TRUE); DecryptFile (file); file.ReadFile (&dw, sizeof (dw)); if (dw) throw _pszFDMCustomizationsErr; LPSTR psz; ReadString (file, &psz); set_Customizer (psz); delete [] psz; file.ReadFile (&m_dwAffiliateID, sizeof (DWORD)); file.ReadFile (&dw, sizeof (dw)); while (dw--) { vmsFDMBanner banner; file.ReadFile (&banner.dwSize, sizeof (DWORD)); banner.pbImage = new BYTE [banner.dwSize]; file.ReadFile (banner.pbImage, banner.dwSize); ReadString (file, &banner.pszLinksTo); file.ReadFile (banner.szType, 4); AddBanner (banner); } file.ReadFile (&m_bUseBtn, sizeof (m_bUseBtn)); if (m_bUseBtn) { ReadString (file, &m_Btn.pszText); ReadString (file, &m_Btn.pszLinksTo); file.ReadFile (&m_Btn.dwSize, sizeof (DWORD)); m_Btn.pbIcon = new BYTE [m_Btn.dwSize]; file.ReadFile (m_Btn.pbIcon, m_Btn.dwSize); } file.ReadFile (&m_bShowFDMCustBtn, sizeof (BOOL)); }
void WinFileCrypter::decrypt() { isDone_ = DecryptFile(filename_.c_str(), 0) != FALSE; }