Hello,
I have a problem I am using the Encrypt and Decrypt command.
But instead of perfectly deciphering the text.
I have random characters randomly.
At first glance it comes from the fact that I write in a file. When I put the text encrypt in a field. I do not have this problem.
I opened the text file. I think it's due to the format of the text file where line breaks are not well converted.
Do you have an idea?
thanks
Krynn
Encrypt error
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: Encrypt error
Bonsoir Krynn,
quick guess:
Do you use BINFILE when writing and reading your encrypted stuff to/from file?
If not, do so and try again.
Encryptring text results in BINARY data!
Best
Klaus
quick guess:
Do you use BINFILE when writing and reading your encrypted stuff to/from file?
If not, do so and try again.
Encryptring text results in BINARY data!
Best
Klaus
Re: Encrypt error
no, I do not use binfile
I'm doing the test tonight
Thank you
I'm doing the test tonight
Thank you
Re: Encrypt error
Hi,
binary data (as in the result from 'encrypt') is a pest to handle/ display/ read. Converted to hex the data become much more amiable - check this:
The functions convert ugly binary data:
to beautiful hex data (B2H):
or back (H2B). You see the difference?
For the encryption/ decryption you may use these functions:
As a bonus they come with a salt, means the encrypted data will look different each time you'll encrypt the same base data ;-)
Another bonus: There's a citation link in the first examples for Mark Smith's web site. It's strongly recommended to have a look at it!
Have fun!
binary data (as in the result from 'encrypt') is a pest to handle/ display/ read. Converted to hex the data become much more amiable - check this:
Code: Select all
function B2H pString -- from libHash-Hmac V 2.3, http://marksmith.on-rev.com/revstuff/
repeat for each byte c in pString
get bytetonum(c)
put baseconvert(it,10,16) into tTemp
if it < 16 then put "0" before tTemp
put tTemp after tHex
end repeat
return tolower(tHex)
end B2H
function H2B pString -- from libHash-Hmac V 2.3, http://marksmith.on-rev.com/revstuff/
repeat with n = 1 to length(pString) - 1 step 2
put numtobyte(baseconvert(byte n to n + 1 of pString, 16, 10)) after tBin
end repeat
return tBin
end H2B
Code: Select all
Salted__40046503…,^D7ˆMWtCÄ…°‰§î†_žÌ˜Mà‰½_Áë÷
Code: Select all
53616c7465645f5f3430303436353033852c5e4437884d7f577443c485b089a7ee865f9ecc980f4de08905bd5fc1ebf7
For the encryption/ decryption you may use these functions:
Code: Select all
function encStrg theStrg, thePass
put char -1 of the millisecs into MyChar
set the randomSeed to MyChar & MyChar & MyChar
put random(900000000) + 99999999 into MySalt
delete char 1 of MySalt
encrypt theStrg using "aes-256-cbc" with password thePass and salt MySalt
get B2H(it)
return it
end encStrg
function decStrg theStrg, thePass
put H2B(theStrg) into MyVar
decrypt MyVar using "aes-256-cbc" with password thePass
return it
end decStrg
Another bonus: There's a citation link in the first examples for Mark Smith's web site. It's strongly recommended to have a look at it!
Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
Re: Encrypt error
Hello AxWald,
Your appoche seems very relevant in order to get rid of all the special characters.
So I followed your advice and adapt my code.
And strength is found that it works great. I adopted it.
I have a question, I am not a specialist in the code, and I did not really understand the interest.
Hello Klaus,
I did not test your solution. But I will do it occasionally, I think it will be useful for other functions.
thank you
Your appoche seems very relevant in order to get rid of all the special characters.
So I followed your advice and adapt my code.
And strength is found that it works great. I adopted it.
I have a question, I am not a specialist in the code, and I did not really understand the interest.
Code: Select all
put char-of-the-millisecs into MyChar
set the randomSeed to MyChar & MyChar & MyChar
put random (900000000) + 99999999 into MySalt
delete char 1 of MySalt
Hello Klaus,
I did not test your solution. But I will do it occasionally, I think it will be useful for other functions.
thank you