des()

Read(130) Label: des, encryption, decryption,

Description:

Perform DES symmetric encryption.

Syntax:

des(input,key,iv;charset)

Note:

The function uses DES symmetric encryption algorithm to encrypt/decrypt parameter input.

 

key is the access key. Initiation vector parameter iv is only needed when CBC encryption mode is used; use ECB encryption mode by default when @c option representing the CBC mode is absent.

 

Usually parameters input, key and iv are BLOB type; the function also supports automatic string encoding.

 

key must have 8 bytes at least. Note that it must have 8 bytes after encoding if the to-be-encrypted value is a string.

 

iv must have 8 bytes at least. Note that it must have 8 bytes after encoding if the to-be-encrypted value is a string.

Parameter:

input

Data to be encrypted/decrypted

key

Access key

iv

Initiation vector

charset

Character set, which is utf-8 by default;

No need to set up this parameter when both input and key are BLOB type

Option:

@d

Perform decryption. Values of parameters key, iv and charset should be same for encryption and decryption

@c

Use CBC encryption mode; use the default mode when parameter iv is absent

@n

Use NoPadding; in this case the number of bytes in input must be the integer multiple of 8, otherwise error will be reported

Return value:

BLOB value

Example:

Encryption and decryption:

 

A

 

1

Hello World!

 

2

v7wz+QhT

 

3

=charencode(A1; "GBK")

Generate a BLOB value using A1’s string.

4

=charencode(A2; "GBK")

Generate a 8-byte BLOB value using A2’s string.

5

=des(A3,A4)

Encrypt A3 using DES symmetric encryption mode while setting up A4 as the access key, and return a BLOB value.

6

=des@d(A5,A4)

Use @d option to decrypt A5 – the access key must be consistent with that in A5’s encryption, and return a BLOB value.

7

=charencode(A6;"GBK")

Generate a string using A6’s BLOB value and return the result: Hello World!

CBC encryption mode:

 

A

 

1

Hello World!

 

2

v7wz+QhTvq

 

3

abcdefgh

 

4

=des@c(A1,A2,A3;"utf-8")

@c option enables using the CBC encryption mode; A3 is the initiation vector and the character set is utf-8; the encoded access key has 10 bytes and the initiation vector has 8 bytes.

5

=des@cd(A4,A2,A3)

Decrypt A4 – access key and initiation vector must be consistent with those in A4’s encryption and use the default utf-8 as parameter charset is absent, and return a BLOB value.

6

=charencode(A5;"utf-8")

Generate a string using A5’s BLOB value and return the result: Hello World!

NoPadding:

 

A

 

1

Hello!!

 

2

v7w

 

3

=charencode(A1;"unicode" )

Generate a 16-byte BLOB value using A1’s string.

4

=charencode(A2;"unicode")

Generate an 8-byte BLOB value using A2’s string.

5

=des@n(A3,A4)

@n option enables NoPadding; in this case the number of bytes in parameter input must be the integer multiple of 8; return a BLOB value.

6

=des@nd(A5,A4)

Decrypt A5.

7

=charencode(A6;"unicode")

Generate a string using A6’s BLOB value and return same result as A1.