[Gambas-user] Crypting single files

Tobias Boege taboege at gmail.com
Fri May 25 13:56:04 CEST 2018


On Fri, 25 May 2018, Benoît Minisini wrote:
> 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.
> 

To make the decision easier: gb.openssl has only symmetric encryption
right now. But yes, if you want asymmetric encryption, you should shell
out to the `openssl` or `gpg` utilities.

For another project, I'll soon, as time allows, be looking into asymmetric
encryption with OpenSSL. If that bears fruit, I'll add it to gb.openssl
as well.

> By the way: I have just upgraded to Ubuntu 18.10, and now compiling
> gb.openssl complains about deprecated functions.
> 

How many? I'm running 1.1.0h (27 Mar 2018) and I only get complaints
about two uses of RAND_pseudo_bytes. But I'm away over the weekend
and can't take a look. (Ceterum censeo... I would also be reluctant to,
because a function deprecated in >= 1.1.0 is guaranteed to be required
by that Frankenssl from PICCORO's 1980s Debian.)

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk


More information about the User mailing list