AES128CBCdecrypt and AES128CBCencrypt (String functions): Difference between revisions
m (add many details and example) |
m (→See also: use template) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{Template:String:AES128CBCdecrypt and AES128CBCencrypt subtitle}} | {{Template:String:AES128CBCdecrypt and AES128CBCencrypt subtitle}} | ||
<var>AES128CBCdecrypt</var> and <var>AES128CBCencrypt</var> are synonyms for the [[String class]] function that applies the DEA (Data Encryption Algorithm) using a 128-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. | <var>AES128CBCdecrypt</var> and <var>AES128CBCencrypt</var> are synonyms for the [[String class]] function that applies the DEA (Data Encryption Algorithm) using a 128-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. | ||
Line 54: | Line 52: | ||
%iv = 'abcdefgh16161616' | %iv = 'abcdefgh16161616' | ||
%ls = %string:aes128cbcencrypt(%key) | %ls = %string:aes128cbcencrypt(%key, %iv) | ||
[[PrintText statement|printText]] {~} is {%ls:stringTohex} | [[PrintText statement|printText]] {~} is {%ls:stringTohex} | ||
printText {~} is: {%ls:aes128cbcdecrypt(%key)} | printText {~} is: {%ls:aes128cbcdecrypt(%key, %iv)} | ||
end | end | ||
</p> | </p> | ||
The result is: | The result is: | ||
<p class="output">%ls:stringTohex is: 432A1AA959C6B064E11C1B12738DC6F247098971B4CFEC6720743AD66F5C32BB | <p class="output">%ls:stringTohex is: 432A1AA959C6B064E11C1B12738DC6F247098971B4CFEC6720743AD66F5C32BB | ||
%ls:aes128cbcdecrypt(%key) is: onetwothreefour0onetwothreefour0 | %ls:aes128cbcdecrypt(%key, %iv) is: onetwothreefour0onetwothreefour0 | ||
</p> | </p> | ||
==See also== | ==See also== | ||
<ul> | <ul> | ||
<li>< | <li>Additional AES methods: | ||
<ul> | |||
{{Template:AES crypto methods}} | |||
</ul></li> | |||
<li>< | <li>Additional two-way ciphers: | ||
<ul> | |||
{{Template:DEA crypto methods}} | |||
<li>[[RC4decrypt and RC4encrypt (String functions)]]</li> | |||
</ul></li> | |||
<li><var> | <li><var>String</var> hashes: | ||
<ul> | |||
< | {{Template:Digest methods}} | ||
</ul></li> | |||
</ul> | </ul> | ||
{{Template:String:AES128CBCdecrypt and AES128CBCencrypt footer}} | {{Template:String:AES128CBCdecrypt and AES128CBCencrypt footer}} |
Latest revision as of 17:03, 20 May 2016
AES128CBC encryption or decryption (String class)
[Introduced in Model 204 7.6]
AES128CBCdecrypt and AES128CBCencrypt are synonyms for the String class function that applies the DEA (Data Encryption Algorithm) using a 128-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:aes128cbcencrypt(%key):aes128cbcdecrypt(%key) eq %string
You can use AES128CBCdecrypt to "document" that you are decrypting, and use AES128CBCencrypt to "document" that you are encrypting. You can use AES128CBCdecrypt and AES128CBCencrypt interchangeably on the rest of this page.
Syntax
%outString = string:AES128CBCdecrypt( key, initVector) Throws UnsupportedCrypto, InvalidCryptoKey, InvalidCryptoData, InvalidCryptoInitVector
%outString = string:AES128CBCencrypt( 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 | A 16-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 AES128CBCdecrypt and decrypting with AES128CBCencrypt.
- The AES128CBCdecrypt and AES128CBCencrypt functions are available as of Model 204 7.6.
Examples
In the following example, the output string from the AES128CBCencrypt 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 %iv is string len 16 %string = 'onetwothreefour0onetwothreefour0' %key = '1234567816161616' %iv = 'abcdefgh16161616' %ls = %string:aes128cbcencrypt(%key, %iv) printText {~} is {%ls:stringTohex} printText {~} is: {%ls:aes128cbcdecrypt(%key, %iv)} end
The result is:
%ls:stringTohex is: 432A1AA959C6B064E11C1B12738DC6F247098971B4CFEC6720743AD66F5C32BB %ls:aes128cbcdecrypt(%key, %iv) is: onetwothreefour0onetwothreefour0
See also
- Additional AES methods:
- 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)
- AES256CBCdecrypt and AES256CBCencrypt (String functions)
- Additional two-way ciphers:
- DEA64decrypt and DEA64encrypt (String functions)
- DEA128decrypt and DEA128encrypt (String functions)
- DEA192decrypt and DEA192encrypt (String functions)
- DEA64CBCdecrypt and DEA64CBCencrypt (String functions)
- DEA128CBCdecrypt and DEA128CBCencrypt (String functions)
- DEA192CBCdecrypt and DEA192CBCencrypt (String functions)
- RC4decrypt and RC4encrypt (String functions)
- String hashes: