DEA64CBCdecrypt and DEA64CBCencrypt (String functions): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (add many details and example)
m (typo)
Line 11: Line 11:
</p>
</p>
You can use <var>DEA64CBCdecrypt</var> to "document" that you are decrypting, and
You can use <var>DEA64CBCdecrypt</var> to "document" that you are decrypting, and
use <var>DEA64CBCencrypt</var> to "document" that you are enrypting. You can use <var>DEA64CBCdecrypt</var> and <var>DEA64CBCencrypt</var> interchangeably on the rest of this page.
use <var>DEA64CBCencrypt</var> to "document" that you are encrypting. You can use <var>DEA64CBCdecrypt</var> and <var>DEA64CBCencrypt</var> interchangeably on the rest of this page.


==Syntax==
==Syntax==

Revision as of 22:43, 11 March 2016

DEA64CBC encryption or decryption (String class)

[Introduced in Model 204 7.6]


DEA64CBCdecrypt and DEA64CBCencrypt are synonyms for the String class function that applies the DEA (Data Encryption Algorithm) using a 64-bit symmetric key to decrypt or encrypt each 64-bit block of input text. CBC (Cipher Block Chaining) refers to a randomizing tactic whereby the result of applying the DEA cipher to a 64-bit block is combined with the next block before its encryption. An initialization vector is used in the first block to make its encryption unique.

For more details about how the algorithm works, see Data Encryption Standard and Block Chaining (CBC) Cipher Block Chaining (CBC).

The length of the returned string is the same as that of the object string.

DEA is a two-way cipher, so encrypting a string with a key and then decrypting the result of that encryption with the same key produces the original string. That is, the following assertion should always hold:

assert %string:dea64cbcencrypt(%key):dea64cbcdecrypt(%key) eq %string

You can use DEA64CBCdecrypt to "document" that you are decrypting, and use DEA64CBCencrypt to "document" that you are encrypting. You can use DEA64CBCdecrypt and DEA64CBCencrypt interchangeably on the rest of this page.

Syntax

%outString = string:DEA64CBCdecrypt( key, initVector) Throws UnsupportedCrypto, InvalidCryptoKey, InvalidCryptoData, InvalidCryptoInitVector

%outString = string:DEA64CBCencrypt( key, initVector) Throws UnsupportedCrypto, InvalidCryptoKey, InvalidCryptoData, InvalidCryptoInitVector

Syntax terms

%outString A string variable to receive the encrypted or decrypted method object string. Its length is the same as string.
string The string to which the method is applied. string must be a multiple of eight bytes in length; its maximum is 32768 bytes. It may be null.
key An 8-byte (only) string variable whose value is used to encrypt or decrypt the method object, string.
initVector An 8-byte string that is used to randomize the encryption. The initialization vector is used to ensure distinct ciphertexts are produced even when the same plaintext is encrypted multiple times independently with the same key.

Usage notes

  • You are not prevented from creating confusion by encrypting with DEA64CBCdecrypt and decrypting with DEA64CBCencrypt.
  • The DEA64CBCdecrypt and DEA64CBCencrypt functions are available as of Model 204 7.6.

Examples

In the following example, the output string from the DEA64CBCencrypt method is converted to hex using the StringToHex function to reveal its non-displayable characters, then decrypted to return the original input string:

b %ls is longstring %string is longstring %key is string len 8 %iv is string len 8 %string = 'onetwothreefour0onetwothreefour0' %key = '12345678' %iv = 'abcdefgh' %ls = %string:dea64cbcEncrypt(%key, %iv) printText {~} is {%ls:stringTohex} printText {~} is: {%ls:dea64cbcDecrypt(%key, %iv)} end

The result is:

%ls:stringTohex is: 296E1A1F581E26AA8449FACDFDD64898D83D239C9C99D3C3F487D3C30E89C784 %ls:dea64cbcDecrypt(%key, %iv) is: onetwothreefour0onetwothreefour0

See also