Forum Discussion

Ashish_Gupta_15's avatar
Ashish_Gupta_15
Icon for Nimbostratus rankNimbostratus
Oct 07, 2016

AES encrypt - Does it need ONLY alphanumeric value and special characters are not allowed?

https://devcentral.f5.com/wiki/iRules.AES__key.ashx

 

https://devcentral.f5.com/wiki/iRules.AES__encrypt.ashx

 

Does the AES key in the encrypt function need ONLY alphanumeric characters? When I have 64 alphanumeric characters, I am able to use the key to encrypt but using any other character gives an error.

 

AES key with 64 alphanumeric characters :

 

set aes_key "AES 256 zaze9a2r363tccaaaaa79a22r3t1671y4493qq289a34gg2b6kk18ca30bd46fed"
set plain_text "hello"
set encrypted_text [b64encode [AES::encrypt $aes_key "$plain_text"]]
log local0. $encrypted_text
`

Output: gcdUkpFWe9WByZclFCSLfBX1wfojmQNgZRaioU32es6A6uGKHPBDRJn9MAAAAAE= 

AES key with special characters :

`set aes_key "AES 256 xqgdYHgOxAhY5THQKVIAr52SRkKT/uOpmHNpD30ZIoo="
set plain_text "hello"
set encrypted_text [b64encode [AES::encrypt $aes_key "$plain_text"]]
log local0. $encrypted_text
`

Output:
**TCL error: /Common/Test_Rule  - Invalid AES key (line 1)invalid AES key (line 1) invoked from within "AES::encrypt $aes_key "$plain_text""** 

The AES key with special characters was generated by using the below PowerShell :
`$aesManaged = New-Object "System.Security.Cryptography.AesManaged"
$aesManaged.KeySize = 256
$key = $aesManaged.GenerateKey()
$key

If it is supposed to use only the HEX chacters, what is the right way to generate the key which would work in encrypt function? This is because I want to rotate the key. A sample code would be very helpful.