I have a page in my application where users can upload files. When the file has been uploaded I use the encryptBinary function to encrypt the file:
<cffile file="#getTempDirectory()##uploaded.serverFile#"
action="readBinary"
variable="binaryFile">
<cfset encrypted = encryptBinary(binaryFile,application.key,"AES")>
But when I then try to decrypt the file using decryptBinary I get the following error:
An error occurred while trying to encrypt or decrypt your input
string: Invalid padding
The decryption code is (where readFile contains the result of the encryption):
<cfset decrypted = decryptBinary(readFile,application.key,"AES")>
How might I solve this error? Thanks!
Related
$message is retrieved from mysql db
The db tables have utf8_general_ci as character encoding
The following is executed with each connection:
mysqli_query($this->link,"set character set utf-8");
The php file is encoded utf-8
$message=urlencode($message);
When the following command is used:
echo $response = file_get_contents
("https://api.telegram.org/botxxxxxxxxxxxxxx/sendMessage?chat_id=-100xxxxxxx&disable_web_page_preview=TRUE&parse_mode=markdown&text=". $message);
}
If retrieved $message is stored in English: it works
If $message is stored in Arabic: it doesn't work
If $message is entered in Arabic in the file itself (not retrieved from db): it works
What is wrong? I would appreciate your help!
you need to config your MySQL DB character-set manually using phpMyadmin
set it to "utf8"
or programmatically when opening your connection try this code:
$dbcon = mysqli_connect("host","user","pass","db");
mysqli_query($dbcon, "set character_set_server='utf8'");
mysqli_query($dbcon, "set names 'utf8'");
you may need to check the messages in the DB tables and may need
to re-enter your msgs to the DB again if it's misformatted because of the wrong char-set.
it looks like the reason is that the browser still treats $message as "WINDOWS-256" encoded. Everything else is UTF8 encoded!
So iconv resolved the issue.
$message=urlencode($message);
Should be:
$message=urlencode(iconv("WINDOWS-256", "UTF-8", $message));
I don't really know why, but it has done the trick!
I am new to python. I am using Selenium library to automate one use case.I have to upload a file from my local. I want this path of the file to be absolute.
Below is the mentioned piece of code I have written:
${curdir}= OperatingSystem.Get File${CURDIR}\\..\\ImportFiles\\PUIMeasure_Report.xlsx
Choose File //*`[#id='importMeasureForm:measureUploadFileComponent:file'] ${curdir}.
The file is correctly located. When i run it, it is showing the following error in log file.
${curdir} = OperatingSystem . Get File
C:\Users\aha8kor\eclipse-workspace\ActionPlanSmokeTest\Tests\Resources\PO\..\ImportFiles\PUIMeasure_Report.xlsx
Start / End / Elapsed: 20180420 11:16:10.518 / 20180420 11:16:10.523 /
00:00:00.005
11:16:10.519 INFO Getting file
'C:\Users\aha8kor\eclipse-workspace\ActionPlanSmokeTest\Tests\Resources\ImportFiles\PUIMeasure_Report.xlsx'.
11:16:10.523 FAIL UnicodeDecodeError: 'utf8' codec can't decode byte
0xa5 in position 14: invalid start byte
enter image description here
Found the solution after too many attempts.
Instead of using "get file" which resulted in encoding and decoding the issue, I gave the path directly in "Choose File" keyword.
Choose File //*[#id='importMeasureForm:measureUploadFileComponent:file'] ${CURDIR}\ImportFiles\PUIMeasureReport.xlsx
I had messed up the path previously.This is just a workaround to avoid such kind of an issue.
I still want to know as how can i handle such encoding decoding issues with "Get File" method.
Thanks in advance.
I need to check to see if a file is a valid pgp encrypted file or not. Some pgp files that we get have an extension of pgp and some dont. I need to check to see which of the files are pgp encrypted files and which are not. Please let me know if there is a way to tell.
The only certain way is to attempt decrypting the file (e.g. with gpg) and interpret the error output. Unless you limit input to ascii-armored files, in that case you can check for the armor.
The python-gpgme library is a Pythonic wrapper for GPGME, the library allowing programmatic GnuPG access.
If you have some files that may or may not be GnuPG encrypted:
$ head --bytes=1024k < /dev/urandom > lorem
$ head --bytes=1024k < /dev/urandom | gpg --encrypt --recipient DEADBEEF > ipsum
With the gpgme module you can attempt to decrypt the files:
import gpgme
import io
context = gpgme.Context()
for infile_path in ['lorem', 'ipsum']:
with open(infile_path, 'rb') as infile:
outfile = io.BytesIO()
try:
context.decrypt(infile, outfile)
except gpgme.GpgmeError as exc:
if exc.code == gpgme.ERR_NO_DATA:
print(
"Not a GnuPG-encrypted file: ‘{path}’ ({error})".format(
path=infile.name, error=exc.strerror))
else:
print(
"Error decrypting file: ‘{path}’ ({error})".format(
path=infile.name, error=exc.strerror))
else:
print("Successfully decrypted: ‘{path}’".format(
path=infile.name))
That lets you handle three conditions:
The gpgme.Context.decrypt method fails, and the error code is gpgme.ERR_NO_DATA. This means the data stream was not recognised as GnuPG-encrypted data.
The gpgme.Context.decrypt method fails for some other reason. You'll need to decide which other errors you care about here.
The gpgme.Context.decrypt method succeeds. Obviously, the file is a correctly-encrypted file.
According to the docs (http://luasqlite.luaforge.net/lsqlite3.html#sqlite3.open)
In case of an error, the function returns nil, an error code and an
error message.
But I always get the same results no matter if I provide a valid or invalid SQLite file. In fact, if I provide an inexistent file or an invalid path I still get the same results. For example:
db, code, msg = sqlite3.open("foo"))
print(db) -- sqlite database (0x7f9ab1628598)
print(code) -- nil
print(msg) -- nil
How can I catch these errors?
sqlite3.open creates a file if it does not exist. So, providing an inexistent file is not an error.
Providing an invalid path should be an error. Calling sqlite3.open("/foo/bar") will probably give you an error.
Another kind of error is a permission error. Calling sqlite3.open("/foo") if you're running some kind of Unix should give you a permission denied error.
I am trying to create a zip file and save it using DotNetZip library.
But for some reason i get a "Access to the path is denied" error when i try to save it. Code4 is below
Dim zipFile As New ZipFile()
zipFile.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression
zipFile.AddFile(filePath)
Dim tempFilePath As String = "abc.zip"
zipFile.TempFileFolder = "D:\Company Data\Operations\media\test_folder_cover_scan\"
zipFile.Save(tempFilePath) <== error line
I have given all possible access to the folder. I am using .net 3.5. This whole code works in a web service
Please advise
The backslashes in your TempFileFolder are not escaped which might cause a problem. Try using a verbatim string literal instead.
zipFile.TempFileFolder = #"D:\Company Data\Operations\media\test_folder_cover_scan\"
Also, the tempFilePath in your example doesn't include a full path, could it be that it is trying to save the ZIP into a different folder from the one you are expecting (and have assigned permissions to)?
Have you assigned permissions to both the temporary file folder AND the real destination folder?
It looks like you don't have access to where you are trying to save it to. Try opening the command prompt and typing
takeown /f D:\Company Data\Operations\media\test_folder_cover_scan
That should give you ownership to the folder you are trying to save the file to.