Cipher (gb.openssl)

This class wraps the cipher (block and stream) algorithms of OpenSSL. See Wikipedia: Ciphers for a start on ciphers.

Esta clase es estática.

Esta clase actúa com un array estático de sólo lectura.

Propiedades estáticas
List  

Métodos estáticos
IsSupported   Checks if the cipher method Method is supported by the OpenSSL library installed on the system.

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 . For example:

Use "gb.openssl"  'For Gambas Script Only

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
Cipher text (base64): U2FsdGVkX1+j36HLTJVWjG2ciDw2ZOk/dhbdB7aiTOg=
Decrypted: Hello there
ERROR: Decryption failed