comp • gb.openssl • cipher

Cipher (gb.openssl)

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

This class is static.
This class acts like a read-only static array.

Static properties

Static methods
List  
Checks if the cipher method Method is supported by the OpenSSL library installed on the system.
IsSupported  

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:

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