AES256CBCdecrypt and AES256CBCencrypt (String functions): Difference between revisions
(Created page with "{{Template:String:AES256CBCdecrypt and AES256CBCencrypt subtitle}} This page is under construction. ==Syntax== {{Template:String:AES256CBCdecrypt syntax}} {{Template:Str...") |
m (add many details and example) |
||
Line 1: | Line 1: | ||
{{Template:String:AES256CBCdecrypt and AES256CBCencrypt subtitle}} | {{Template:String:AES256CBCdecrypt and AES256CBCencrypt subtitle}} | ||
<var>AES256CBCdecrypt</var> and <var>AES256CBCencrypt</var> are synonyms for the [[String class]] function that applies the DEA (Data Encryption Algorithm) using a 256-bit symmetric key to decrypt or encrypt each 128-bit block of input text. CBC (Cipher Block Chaining) refers to a randomizing tactic whereby the result of applying the AES cipher to a 128-bit block is combined with the next block before the next block's encryption; and so on for each subsequent block. An initialization vector is used in the first block to make its encryption unique. | |||
For more details about how the algorithm works, see [https://en.wikipedia.org/wiki/Data_Encryption_Standard Data Encryption Standard] and [https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher Block Chaining (CBC) Cipher Block Chaining (CBC)]. | |||
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 <b><i>always</i></b> hold: | |||
<p class="code">[[Assert statement|assert]] %string:aes256cbcencrypt(%key):aes256cbcdecrypt(%key) eq %string | |||
</p> | |||
You can use <var>AES256CBCdecrypt</var> to "document" that you are decrypting, and | |||
use <var>AES256CBCencrypt</var> to "document" that you are encrypting. You can use <var>AES256CBCdecrypt</var> and <var>AES256CBCencrypt</var> interchangeably on the rest of this page. | |||
==Syntax== | ==Syntax== | ||
Line 9: | Line 19: | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table> | <table> | ||
<tr><th>%outString</th><td>string</td></tr> | <tr><th>%outString</th> | ||
<td>A string variable to receive the encrypted or decrypted method object <var class="term">string</var>. Its length is the same as <var class="term">string</var>.</td></tr> | |||
<tr><th>string</th> | <tr><th>string</th> | ||
<td>string</td></tr> | <td>The string to which the method is applied. <var class="term">string</var> must be a multiple of sixteen bytes in length; its maximum is 32768 bytes. It may be null.</td></tr> | ||
<tr><th>key</th> | <tr><th>key</th> | ||
<td>string, | <td>A 32-byte (only) string variable whose value is used to encrypt or decrypt the method object, <var class="term">string</var>.</td></tr> | ||
<tr><th>initVector</th> | <tr><th>initVector</th> | ||
<td>string | <td>A 16-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.</td></tr> | |||
</table> | </table> | ||
==Usage notes== | ==Usage notes== | ||
<ul> | |||
<li>You are <b><i>not</i></b> prevented from creating confusion by encrypting with <var>AES256CBCdecrypt</var> and decrypting with <var>AES256CBCencrypt</var>. </li> | |||
<li>The <var>AES256CBCdecrypt</var> and <var>AES256CBCencrypt</var> functions are available as of <var class="product">Model 204</var> 7.6. </li> | |||
</ul> | |||
==Examples== | ==Examples== | ||
In the following example, the output string from the <var>AES256CBCencrypt</var> method is converted to hex using the <var>[[StringToHex (String function)|StringToHex]]</var> function to reveal its non-displayable characters, then decrypted to return the original input string: | |||
<p class="code">b | |||
%ls is longstring | |||
%string is longstring | |||
%key is string len 32 | |||
%iv is string len 16 | |||
%string = 'onetwothreefour0onetwothreefour0' | |||
%key = '12345678161616162424242432323232' | |||
%iv = 'abcdefgh16161616' | |||
%ls = %string:aes256cbcencrypt(%key, %iv) | |||
[[PrintText statement|printText]] {~} is {%ls:stringTohex} | |||
printText {~} is: {%ls:aes256cbcdecrypt(%key, %iv)} | |||
end | |||
</p> | |||
The result is: | |||
<p class="output">%ls:stringTohex is: BD9E29B6AE9F796AECEDFC69ACBF0030AB4CFED68139EB6518262C648D133DF3 | |||
%ls:aes256cbcdecrypt(%key, %iv) is: onetwothreefour0onetwothreefour0 | |||
</p> | |||
==See also== | ==See also== | ||
<ul> | |||
<li><var>[[AES128decrypt and AES128encrypt (String functions)]]</var> </li> | |||
<li><var>[[AES192decrypt and AES192encrypt (String functions)]]</var> </li> | |||
<li><var>[[AES256decrypt and AES256encrypt (String functions)]]</var> </li> | |||
<li><var>[[AES128CBCdecrypt and AES128CBCencrypt (String functions)]]</var> </li> | |||
<li><var>[[AES192CBCdecrypt and AES192CBCencrypt (String functions)]]</var> </li> | |||
</ul> | |||
{{Template:String:AES256CBCdecrypt and AES256CBCencrypt footer}} | {{Template:String:AES256CBCdecrypt and AES256CBCencrypt footer}} |
Revision as of 23:57, 11 March 2016
AES256CBC encryption or decryption (String class)
[Introduced in Model 204 7.6]
AES256CBCdecrypt and AES256CBCencrypt are synonyms for the String class function that applies the DEA (Data Encryption Algorithm) using a 256-bit symmetric key to decrypt or encrypt each 128-bit block of input text. CBC (Cipher Block Chaining) refers to a randomizing tactic whereby the result of applying the AES cipher to a 128-bit block is combined with the next block before the next block's encryption; and so on for each subsequent block. 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.
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:aes256cbcencrypt(%key):aes256cbcdecrypt(%key) eq %string
You can use AES256CBCdecrypt to "document" that you are decrypting, and use AES256CBCencrypt to "document" that you are encrypting. You can use AES256CBCdecrypt and AES256CBCencrypt interchangeably on the rest of this page.
Syntax
%outString = string:AES256CBCdecrypt( key, initVector) Throws UnsupportedCrypto, InvalidCryptoKey, InvalidCryptoData, InvalidCryptoInitVector
%outString = string:AES256CBCencrypt( 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 sixteen bytes in length; its maximum is 32768 bytes. It may be null. |
key | A 32-byte (only) string variable whose value is used to encrypt or decrypt the method object, string. |
initVector | A 16-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 AES256CBCdecrypt and decrypting with AES256CBCencrypt.
- The AES256CBCdecrypt and AES256CBCencrypt functions are available as of Model 204 7.6.
Examples
In the following example, the output string from the AES256CBCencrypt 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 32 %iv is string len 16 %string = 'onetwothreefour0onetwothreefour0' %key = '12345678161616162424242432323232' %iv = 'abcdefgh16161616' %ls = %string:aes256cbcencrypt(%key, %iv) printText {~} is {%ls:stringTohex} printText {~} is: {%ls:aes256cbcdecrypt(%key, %iv)} end
The result is:
%ls:stringTohex is: BD9E29B6AE9F796AECEDFC69ACBF0030AB4CFED68139EB6518262C648D133DF3 %ls:aes256cbcdecrypt(%key, %iv) is: onetwothreefour0onetwothreefour0
See also
- AES128decrypt and AES128encrypt (String functions)
- AES192decrypt and AES192encrypt (String functions)
- AES256decrypt and AES256encrypt (String functions)
- AES128CBCdecrypt and AES128CBCencrypt (String functions)
- AES192CBCdecrypt and AES192CBCencrypt (String functions)