AES128decrypt and AES128encrypt (String functions): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (typo)
m (→‎See also: add templates)
Line 56: Line 56:
==See also==
==See also==
<ul>
<ul>
<li><var>[[AES192decrypt and AES192encrypt (String functions)]]</var> </li>
<li>Additional AES methods:
<ul>
{{Template:AES crypto methods}}
</ul></li>


<li><var>[[AES256decrypt and AES256encrypt (String functions)]]</var> </li>
<li>Additional two-way ciphers:
<ul>
{{Template:DEA crypto methods}}
<li>[[RC4decrypt and RC4encrypt (String functions)]]</li>
</ul></li>


<li><var>[[AES128CBCdecrypt and AES128CBCencrypt (String functions)]]</var> </li>
<li><var>String</var> one-way ciphers:
<ul>
<li><var>[[MD5digest (String function)|MD5digest]]</var> </li>  


<li><var>[[AES192CBCdecrypt and AES192CBCencrypt (String functions)]]</var> </li>
<li><var>[[SHAdigest (String function)|SHAdigest]]</var> </li>


<li><var>[[AES256CBCdecrypt and AES256CBCencrypt (String functions)]]</var> </li>
<li><var>[[SHA224digest (String function)|SHA224digest]]</var> </li>
 
<li><var>[[SHA256digest (String function)|SHA256digest]]</var> </li>
</ul></li>
</ul>
</ul>


{{Template:String:AES128decrypt and AES128encrypt footer}}
{{Template:String:AES128decrypt and AES128encrypt footer}}

Revision as of 20:25, 16 March 2016

AES128 encryption or decryption (String class)

[Introduced in Model 204 7.6]


AES128decrypt and AES128encrypt are synonyms for the String class function that applies the AES (Advanced Encryption Standard) using a 128-bit symmetric key to decrypt or encrypt each 128-bit block of input text. For more details about how the algorithm works, see Advanced Encryption Standard.

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

AES 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:aes128encrypt(%key):aes128decrypt(%key) eq %string

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

Syntax

%outString = string:AES128decrypt( key) Throws UnsupportedCrypto, InvalidCryptoKey, InvalidCryptoData

%outString = string:AES128encrypt( key) Throws UnsupportedCrypto, InvalidCryptoKey, InvalidCryptoData

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 sixteen bytes in length; its maximum is 32768 bytes. It may be null.
key A 16-byte (only) string variable whose value is used to encrypt or decrypt the method object, string.

Usage notes

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

Examples

In the following example, the output string from the AES128encrypt 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 16 %string = 'onetwothreefour0onetwothreefour0' %key = '1234567816161616' %ls = %string:aes128encrypt(%key) printText {~} is {%ls:stringTohex} printText {~} is: {%ls:aes128decrypt(%key)} end

The result is:

%ls:stringTohex is: 5B97010EF3A73C8C286C50B171C9AF455B97010EF3A73C8C286C50B171C9AF45 %ls:aes128decrypt(%key) is: onetwothreefour0onetwothreefour0

See also