[Gambas-user] Crypting single files
Benoît Minisini
g4mba5 at gmail.com
Fri May 25 13:08:50 CEST 2018
Le 25/05/2018 à 13:05, Tobias Boege a écrit :
> On Fri, 25 May 2018, Rolf-Werner Eilert wrote:
>> There is a gb.crypt component, but it is meant to encrypt passwords only.
>>
>> Is there a component that has some easy-to-handle functions to encrypt
>> files?
>>
>> Or if not, how do you handle this?
>>
>
> gb.openssl does this. Example:
>
> Public Sub Main()
>
> Dim sTemp As String = Temp$()
>
> File.Save(sTemp, CStr(Now))
> Print "Original data:";; File.Load(sTemp)
>
> File.Save(sTemp, Cipher["BF-CBC"].EncryptSalted(File.Load(sTemp), "passphrase", "salt"))
>
> Print "Encrypted data:";; Base64$(File.Load(sTemp))
> Print "Decrypted data:";; Cipher["BF-CBC"].DecryptSalted(File.Load(sTemp), "passphrase")
>
> Print "Wrongly decrypted data:";; Cipher["BF-CBC"].DecryptSalted(File.Load(sTemp), "Passphrase")
>
> End
>
> Original data: 05/25/2018 10:58:45.768
> Encrypted data: U2FsdGVkX19zYWx0AAAAAEQ8/7vYGZRMqEpmhf7SssiQJkBlcT4tmw==
> Decrypted data: 05/25/2018 10:58:45.768
> ' Last line raises an error because the password is wrong
>
> Note that the encrypted data is base64 encoded because it is binary
> gibberish that you don't want to print to a terminal.
>
> Indexing the Cipher class with a cipher method (here "BF-CBC") gives you
> an object, which you can use to encrypt and decrypt arbitrary strings.
> The Cipher.List property gives you a list of all ciphers available from
> the openssl crypto library on your system.
>
> Regards,
> Tobi
>
Just a remark: you have first to decide whether you want symmetric or
asymmetric encryption.
By the way: I have just upgraded to Ubuntu 18.10, and now compiling
gb.openssl complains about deprecated functions.
Regards,
--
Benoît Minisini
More information about the User
mailing list