[Gambas-user] Cipher doesn't read ciphered text

Rolf-Werner Eilert rwe-sse at osnanet.de
Tue Sep 29 15:57:23 CEST 2020


Am 29.09.20 um 15:18 schrieb T Lee Davidson:
> On 9/29/20 7:17 AM, Rolf-Werner Eilert wrote:
>> I played around with Cipher, extending it by loading a small ASCII 
>> text file (2016 Bytes) with File.Load. The string is crypted and when 
>> I want it decrypted, Gambas says "Decryption failed".
>>
>> A short string like "hello world" is ok, it does even accept umlauts. 
>> So, where's the problem? Too long? Unfortunately, the documentation 
>> isn't complete and the error message doesn't say why.
>>
>> Regards
>> Rolf
> 
> Does decryption fail if you explicitly set a string variable to the 
> encrypted text instead of loading from a file?
> How was the ASCII text file created?
> 
> I ask because some text editors can be set to add a newline at the end 
> of a file if there is not one. Perhaps examine the text file with a hex 
> editor, or try something like:
> sEncryptedText = Trim(File.Load("encrypted.txt"))
> 
> If it's not that, can you provide an example project?
> 
> 

This is the code, it's from the example and slightly altered. I used a 
TextEdit to show the results, then saved the crypted text to investigate 
with a hex editor. (I use My.File here, as the original one contains a 
name.)

   t$ = File.Load("/klein/kartei/T18/My.File")
   't$ = "Hallo öäüß"
   sCipher = Cipher["AES-256-CBC"].EncryptSalted(t$, "secret")
   TextEdit1.Text = "Cipher text (base64): " & Base64$(sCipher) & Chr$(10)
   sData = Cipher["AES-256-CBC"].DecryptSalted(sCipher, "secret")
   TextEdit1.Text &= "Decrypted: " & sData & Chr$(10)

   File.Save("~/Gambas3/testEditor/test.cipher", sCipher)



It fails in the line "sDate = Cipher...", so it cannot decrypt the 
string it crypted before. I tried another, even longer file, and it ran 
flawlessly. So I cannot make out what caused the error.

Both files are made up the same way, they contain a CR+LF pair after 
each line to make the files compatible to an older Windows program that 
reads them. But that doesn't seem to be the reason.

Regards
Rolf


More information about the User mailing list