[Gambas-user] open-ssl

Christof Thalhofer chrisml at deganius.de
Sat Sep 29 09:35:46 CEST 2018


Am 27.09.2018 um 17:16 schrieb Tobias Boege:

> En- and decryption is done using the Cipher class. First, you have to settle
> on a cipher, say AES256 in CBC mode. You can get a list of ciphers that your
> local openssl supports from Cipher.List. You'll see that "AES-256-CBC" is a
> supported method (I suppose virtually everywhere). You use this string as an
> index into the Cipher class to get a .Cipher.Method object which can do en-
> and decryption, see [1]. For example:
> 
>   Public Sub Main()
>     Dim sCipher, sData As String
> 
>     sCipher = Cipher["AES-256-CBC"].EncryptSalted("Hello there", "secret")
>     Print "Cipher text (base64):";; Base64$(sCipher)
>     sData = Cipher["AES-256-CBC"].DecryptSalted(sCipher, "secret")
>     Print "Decrypted:";; sData
> 
>     Try Cipher["AES-256-CBC"].DecryptSalted(sCipher, "wrong")
>     If Error Then Print "ERROR:";; Error.Text
>   End
> 
> produces the following output:
> 
>   Cipher text (base64): U2FsdGVkX1+j36HLTJVWjG2ciDw2ZOk/dhbdB7aiTOg=
>   Decrypted: Hello there
>   ERROR: Decryption failed

This was concise. I pasted it into the doc:

http://gambaswiki.org/wiki/comp/gb.openssl/cipher

Alles Gute

Christof Thalhofer

-- 
Dies ist keine Signatur

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20180929/95157431/attachment.sig>


More information about the User mailing list