Platforms to show: All Mac Windows Linux Cross-Platform

Back to CipherMBS class.

CipherMBS.CipherInit(key as memoryblock, IV as memoryblock, Encrypt as boolean) as Boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Encryption and Hash MBS Encryption Plugin 13.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Initializes the cipher for encryption or decryption.

We added for 17.3 a new boolean result:

Returns true in case of success and key length is okay.
Returns false in case of failures like out of memory, wrong key length.

Even if key length is wrong, we initialize (as with older versions before) but may crop the key length to default length.
AES 128 uses 16 byte key length, AES 256 uses 32 byte key length.
Key and IV are both filled with zeros to reach the minimum length.

key: The key to use.
IV: Optional, the initial vector.

You can use IVLength and KeyLength properties to learn how long those should be.

CipherMBS.Clear

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Encryption and Hash MBS Encryption Plugin 13.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Clears the current state.

CipherMBS.Constructor   Private

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Encryption and Hash MBS Encryption Plugin 13.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
The private constructor.

CipherMBS.Control(Type as Integer, Arg as Integer, Data as Ptr)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Encryption and Hash MBS Encryption Plugin 23.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Allows various cipher specific parameters to be determined and set.

See OpenSSL documentation for EVP_CIPHER_CTX_ctrl function.

CipherMBS.DecryptInit(key as memoryblock, IV as memoryblock = nil) as Boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Encryption and Hash MBS Encryption Plugin 13.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Initializes the cipher for decrypting.
Example
dim key as string = "mysecretkey"
dim encrypted as string = "6IcB9bpDwOjjONErhYQ6c7+Fb4qszsUNZVU0iThLYqOu7chJ7MG2nwSpRBUY0ZC3"

encrypted = DecodeBase64(encrypted)

dim c as CipherMBS = CipherMBS.aes_128_cbc
call c.DecryptInit key

dim s as string = c.ProcessString(Encrypted)+c.FinalizeAsString

Break // "In welcher Stadt steht das Bundeshaus?" is now in s.

We added for 17.3 a new boolean result:

Returns true in case of success and key length is okay.
Returns false in case of failures like out of memory, wrong key length.

Even if key length is wrong, we initialize (as with older versions before) but may crop the key length to default length.
AES 128 uses 16 byte key length, AES 256 uses 32 byte key length.
Key and IV are both filled with zeros to reach the minimum length.

key: The key to use.
IV: Optional, the initial vector.

You can use IVLength and KeyLength properties to learn how long those should be.

For AES the length of the key defines whether you get 128, 192 or 256 bit encryption. Pass some other key length will return an error. Best is usually to put a hashing algorithm before to make sure the key has the required bit length, e.g. use SHA256MBS class.

Some examples using this method:

CipherMBS.EncryptInit(key as memoryblock, IV as memoryblock = nil) as Boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Encryption and Hash MBS Encryption Plugin 13.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Initializes the cipher for encrypting.
Example
dim c as CipherMBS = CipherMBS.aes_128_cfb128
dim CKey as MemoryBlock = "1234567812345678"
dim CIV as MemoryBlock
dim data as string = "Hello World. Just a test!"

call c.EncryptInit Ckey, CIV

dim output as string = c.ProcessString(data)
output = output + c.FinalizeAsString

MsgBox EncodeHex(output)

We added for 17.3 a new boolean result:

Returns true in case of success and key length is okay.
Returns false in case of failures like out of memory, wrong key length.

Even if key length is wrong, we initialize (as with older versions before) but may crop the key length to default length.
AES 128 uses 16 byte key length, AES 256 uses 32 byte key length.
Key and IV are both filled with zeros to reach the minimum length.

key: The key to use.
IV: Optional, the initial vector.

You can use IVLength and KeyLength properties to learn how long those should be.

For AES the length of the key defines whether you get 128, 192 or 256 bit encryption. Pass some other key length will return an error. Best is usually to put a hashing algorithm before to make sure the key has the required bit length, e.g. use SHA256MBS class.

Some examples using this method:

CipherMBS.FinalizeAsMemory as memoryblock

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Encryption and Hash MBS Encryption Plugin 13.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Finalizes en/decryption and returns last data.

CipherMBS.FinalizeAsString as String

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Encryption and Hash MBS Encryption Plugin 13.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Finalizes en/decryption and returns last data.
Example
dim c as CipherMBS = CipherMBS.aes_128_cfb128
dim CKey as MemoryBlock = "1234567812345678"
dim CIV as MemoryBlock
dim data as string = "Hello World. Just a test!"

call c.EncryptInit Ckey, CIV

dim output as string = c.ProcessString(data)
output = output + c.FinalizeAsString

MsgBox EncodeHex(output)

Returned string does not contain text, but binary data.
Please do not store in text fields in database without using EncodeHex or EncodeBase64 to make it a text string.

Some examples using this method:

CipherMBS.GetGCMTag(Size as Integer = 16) as MemoryBlock

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Encryption and Hash MBS Encryption Plugin 23.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Queries tag value for AES GCM.
Example

Dim c As CipherMBS = CipherMBS.aes_256_gcm

// encrypt it
Dim key As String = "12345678"

Call c.EncryptInit(key)

Dim p1 As String = c.ProcessString("Hello World")
Dim p2 As String = c.FinalizeAsString
Dim encrypted As String = p1 + p2
Dim TagValue As MemoryBlock = c.GetGCMTag

Break

// decrypt it
Dim d As CipherMBS = CipherMBS.aes_256_gcm
Call d.DecryptInit key

Dim d1 As String = d.ProcessString(encrypted)

d.SetGCMTag TagValue

Dim d2 As String = d.FinalizeAsString
Dim decrypted As String = d1 + d2

Break

Calls the Control method with type EVP_CTRL_GCM_GET_TAG (16).
Raises exception in case of an error.

CipherMBS.ProcessFile(InputFile as FolderItem, OutputFile as FolderItem) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Encryption and Hash MBS Encryption Plugin 14.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Processes content of file.

Plugin will start a preemptive thread to read in file and process all data in chunks and write to output file.
Returns true on success or false on failure. May raise OutOfMemoryException or IOException.
This function works best if called from a thread.

Some examples using this method:

CipherMBS.ProcessMemory(data as memoryblock) as MemoryBlock

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Encryption and Hash MBS Encryption Plugin 13.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Processes data in a memory block.

due to block sizes, the result may be longer or shorter than the input size.

CipherMBS.ProcessString(data as String) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Encryption and Hash MBS Encryption Plugin 13.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Processes data in a string.
Example
dim key as string = "mysecretkey"
dim encrypted as string = "6IcB9bpDwOjjONErhYQ6c7+Fb4qszsUNZVU0iThLYqOu7chJ7MG2nwSpRBUY0ZC3"

encrypted = DecodeBase64(encrypted)

dim c as CipherMBS = CipherMBS.aes_128_cbc
call c.DecryptInit key

dim s as string = c.ProcessString(Encrypted)+c.FinalizeAsString

Break // "In welcher Stadt steht das Bundeshaus?" is now in s.

due to block sizes, the result may be longer or shorter than the input size.

Returned string does not contain text, but binary data.
Please do not store in text fields in database without using EncodeHex or EncodeBase64 to make it a text string.

Some examples using this method:

CipherMBS.SetGCMTag(Data as MemoryBlock)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Encryption and Hash MBS Encryption Plugin 23.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Sets tag value for AES GCM.
Example

Dim c As CipherMBS = CipherMBS.aes_256_gcm

// encrypt it
Dim key As String = "12345678"

Call c.EncryptInit(key)

Dim p1 As String = c.ProcessString("Hello World")
Dim p2 As String = c.FinalizeAsString
Dim encrypted As String = p1 + p2
Dim TagValue As MemoryBlock = c.GetGCMTag

Break

// decrypt it
Dim d As CipherMBS = CipherMBS.aes_256_gcm
Call d.DecryptInit key

Dim d1 As String = d.ProcessString(encrypted)

d.SetGCMTag TagValue

Dim d2 As String = d.FinalizeAsString
Dim decrypted As String = d1 + d2

Break

Calls the Control method with type EVP_CTRL_GCM_SET_TAG (17).
Raises exception in case of an error.

CipherMBS.SetPadding(padding as boolean)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Encryption and Hash MBS Encryption Plugin 13.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Enables padding.

On by default.

The items on this page are in the following plugins: MBS Encryption Plugin.


The biggest plugin in space...