Sets the file options used by LEADTOOLS when loading encrypted files.
#include "ltwrappr.h"
static L_INT LFileSettings::SetDecryptOptions(pOptions)
Pointer to a structure that contains the options used when loading encrypted files.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
The values set by this function are valid only for the current thread. To change the values used by the current thread, this function must be called again from that thread.
These settings are used for loading all encrypted files (DOC, DOCX, PDF, PPT, PPTX, XLS, XLSX, XLSB, etc). An additional password can be provided for loading encrypted PDF files using LFileSettings::SetPDFOptions.
The following scenarios are possible when loading encrypted files:
LFileSettings::SetDecryptOptions
.LFileSettings::SetDecryptOptions
or LFileSettings::SetPDFOptions. Both can also be used.To get the current options used when loading encrypted files, call LFileSettings::GetDecryptOptions.
Win32, x64.
static L_INT EXT_CALLBACK GetPasswordProc(const L_TCHAR* pszFileName, L_TCHAR** ppszPassword, L_VOID* pUserData)
{
UNREFERENCED_PARAMETER(pUserData);
/* A proper implementation would bring up a message box asking the user "please provide a password for the file 'pszFileName'" */
/* We will keep it simple and hardcode a password, but we will need to prevent an infinite loop. So we will not provide the same password more than once for the same file */
static L_TCHAR szOldFileName[L_MAXPATH];
if (!_tcscmp(pszFileName, szOldFileName))
return ERROR_INV_PASSWORD; /* I already tried this password for this file */
L_TCHAR* pszMyPassword = L_TEXT("Excel");
L_INT nRet = LBase::AllocBuffer((_tcslen(pszMyPassword) + 1) * sizeof(L_TCHAR), (L_VOID**)ppszPassword);
if (nRet == SUCCESS)
{
memcpy(*ppszPassword, pszMyPassword, (_tcslen(pszMyPassword) + 1) * sizeof(L_TCHAR));
_tcscpy_s(szOldFileName, _countof(szOldFileName), pszFileName); /* store the filename to indicate that we already provided the password for this filename */
}
return nRet;
}
L_INT TestLoadEncrypted(LBitmapBase* pLBitmap)
{
/* This is an encrypted Excel file which requires the password 'Excel' to load properly */
L_TCHAR* pszFileName = L_TEXT("Encrypted - Encrypted Excel.xlsx");
/* Provide a default password 'DefaultPassword'. If this is not valid, call the GetPasswordProc function */
FILEDECRYPTOPTIONS options;
LFileSettings::GetDecryptOptions(&options, sizeof(FILEDECRYPTOPTIONS));
options.pszPassword = L_TEXT("DefaultPassword");
options.pfnCallback = GetPasswordProc;
options.pUserData = NULL;
LFileSettings::SetDecryptOptions(&options);
LFile file(pLBitmap, pszFileName);
FILEINFO fileInfo = { sizeof(FILEINFO) };
L_INT nRet;
if ((nRet = file.GetInfo(&fileInfo, sizeof(FILEINFO), 0, NULL)) != SUCCESS)
return nRet;
return file.Load(0, ORDER_BGRORGRAY, NULL, &fileInfo);
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document