Todos os produtos
Search
Central de documentação

Edge Security Acceleration:Funções de algoritmos de cifra

Última atualização: Jun 29, 2026

As funções de algoritmos de cifra oferecem criptografia e descriptografia AES, hash SHA-1 e SHA-2, cálculo de HMAC e resumo MD5.

aes_new

Item Descrição
Sintaxe aes_new(config)
Recurso Cria um objeto AES para criptografia posterior com aes_enc() e descriptografia com aes_dec().
Parâmetro O parâmetro config é do tipo dicionário e inclui os seguintes argumentos:
  • key: a chave (tipo string). Obrigatório.
  • salt: o valor salt (tipo string). Opcional.
  • cipher_len: o comprimento da chave. Obrigatório. Valores válidos: 128, 192 e 256.
  • cipher_mode: o modo de criptografia ou descriptografia. Obrigatório. Valores válidos: ecb, cbc, ctr, cfb e ofb.
  • iv: o vetor inicial (tipo string). Opcional.
Valor de retorno Retorna um objeto AES (tipo dicionário) em caso de sucesso ou false em caso de falha.
Exemplo
aes_conf = []                                                                                                                                                                         
plaintext = ''                                                                                                                                                                        
if and($http_mode, eq($http_mode, 'ecb-128')) {                                                                                                                                       
  defina(aes_conf, 'key', 'ab8bfd9f-a1af-4ba2-bbb0-1ee520e3d8bc')                                                                                                                      
  defina(aes_conf, 'salt', '1234567890')                                                                                                                                               
  defina(aes_conf, 'cipher_len', 128)                                                                                                                                                  
  defina(aes_conf, 'cipher_mode', 'ecb')                                                                                                                                               
  plaintext = 'hello aes ecb-128'                                                                                                                                                   
}                                                                                                                                                                                     
if and($http_mode, eq($http_mode, 'cbc-256')) {                                                                                                                                       
  defina(aes_conf, 'key', '146ebcc8-392b-4b3a-a720-e7356f62')                                                                                                                          
  defina(aes_conf, 'cipher_len', 256)                                                                                                                                                  
  defina(aes_conf, 'cipher_mode', 'cbc')                                                                                                                                               
  defina(aes_conf, 'iv', '0123456789abcdef')                                                                                                                                           
  plaintext = 'hello aes cbc-256'                                                                                                                                                   
}                                                                                                                                                                                     
if and($http_mode, eq($http_mode, 'ofb-256')) {                                                                                                                                       
  defina(aes_conf, 'key', '146ebcc8-392b-4b3a-a720-e7356f62')                                                                                                                          
  defina(aes_conf, 'cipher_len', 256)                                                                                                                                                  
  defina(aes_conf, 'cipher_mode', 'ofb')                                                                                                                                               
  defina(aes_conf, 'iv', tochar(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0))                                                                                                                      
  plaintext = 'hello aes ofb-256'                                                                                                                                                   
}                                                                                                                                                                                     

aes_obj = aes_new(aes_conf)                                                                                                                                                           
if not(aes_obj) {                                                                                                                                                                     
  say(concat('aes obj failed'))                                                                                                                                                     
  exit(400)                                                                                                                                                                         
}                                                                                                                                                                                     

ciphertext = aes_enc(aes_obj, plaintext)                                                                                                                                              
plaintext_reverse = aes_dec(aes_obj, ciphertext)                                                                                                                                      

say(concat('plain: ', plaintext))                                                                                                                                                     
say(concat('cipher: ', tohex(ciphertext)))                                                                                                                                            
say(concat('plain_reverse: ', plaintext_reverse))                                                                                                                                     

if ne(plaintext, plaintext_reverse) {                                                                                                                                                 
  say('plaintext ~= plaintext_reverse')                                                                                                                                            
  exit(400)                                                                                                                                                                        
}

aes_enc

Item Descrição
Sintaxe aes_enc(o, s)
Recurso Criptografa dados com AES.
Parâmetro
  • s: o texto simples a criptografar.
  • o: o objeto AES retornado pela função aes_new.
Valor de retorno Retorna o texto cifrado após a criptografia do parâmetro s.
Exemplo
aes_conf = []                                                                                                                                                                         
plaintext = ''                                                                                                                                                                        
if and($http_mode, eq($http_mode, 'ecb-128')) {                                                                                                                                       
  defina(aes_conf, 'key', 'ab8bfd9f-a1af-4ba2-bbb0-1ee520e3d8bc')                                                                                                                      
  defina(aes_conf, 'salt', '1234567890')                                                                                                                                               
  defina(aes_conf, 'cipher_len', 128)                                                                                                                                                  
  defina(aes_conf, 'cipher_mode', 'ecb')                                                                                                                                               
  plaintext = 'hello aes ecb-128'                                                                                                                                                   
}                                                                                                                                                                                     
if and($http_mode, eq($http_mode, 'cbc-256')) {                                                                                                                                       
  defina(aes_conf, 'key', '146ebcc8-392b-4b3a-a720-e7356f62')                                                                                                                          
  defina(aes_conf, 'cipher_len', 256)                                                                                                                                                  
  defina(aes_conf, 'cipher_mode', 'cbc')                                                                                                                                               
  defina(aes_conf, 'iv', '0123456789abcdef')                                                                                                                                           
  plaintext = 'hello aes cbc-256'                                                                                                                                                   
}                                                                                                                                                                                     
if and($http_mode, eq($http_mode, 'ofb-256')) {                                                                                                                                       
  defina(aes_conf, 'key', '146ebcc8-392b-4b3a-a720-e7356f62')                                                                                                                          
  defina(aes_conf, 'cipher_len', 256)                                                                                                                                                  
  defina(aes_conf, 'cipher_mode', 'ofb')                                                                                                                                               
  defina(aes_conf, 'iv', tochar(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0))                                                                                                                      
  plaintext = 'hello aes ofb-256'                                                                                                                                                   
}                                                                                                                                                                                     

aes_obj = aes_new(aes_conf)                                                                                                                                                           
if not(aes_obj) {                                                                                                                                                                     
  say(concat('aes obj failed'))                                                                                                                                                     
  exit(400)                                                                                                                                                                         
}                                                                                                                                                                                     

ciphertext = aes_enc(aes_obj, plaintext)                                                                                                                                              
plaintext_reverse = aes_dec(aes_obj, ciphertext)                                                                                                                                      

say(concat('plain: ', plaintext))                                                                                                                                                     
say(concat('cipher: ', tohex(ciphertext)))                                                                                                                                            
say(concat('plain_reverse: ', plaintext_reverse))                                                                                                                                     

if ne(plaintext, plaintext_reverse) {                                                                                                                                                 
  say('plaintext ~= plaintext_reverse')                                                                                                                                            
  exit(400)                                                                                                                                                                        
}

aes_dec

Item Descrição
Sintaxe aes_dec(o, s)
Recurso Descriptografa dados criptografados com AES.
Parâmetro
  • s: o texto cifrado a descriptografar.
  • o: o objeto AES retornado pela função aes_new.
Valor de retorno Retorna o texto simples após a descriptografia do parâmetro s.
Exemplo
aes_conf = []                                                                                                                                                                         
plaintext = ''                                                                                                                                                                        
if and($http_mode, eq($http_mode, 'ecb-128')) {                                                                                                                                       
  defina(aes_conf, 'key', 'ab8bfd9f-a1af-4ba2-bbb0-1ee520e3d8bc')                                                                                                                      
  defina(aes_conf, 'salt', '1234567890')                                                                                                                                               
  defina(aes_conf, 'cipher_len', 128)                                                                                                                                                  
  defina(aes_conf, 'cipher_mode', 'ecb')                                                                                                                                               
  plaintext = 'hello aes ecb-128'                                                                                                                                                   
}                                                                                                                                                                                     
if and($http_mode, eq($http_mode, 'cbc-256')) {                                                                                                                                       
  defina(aes_conf, 'key', '146ebcc8-392b-4b3a-a720-e7356f62')                                                                                                                          
  defina(aes_conf, 'cipher_len', 256)                                                                                                                                                  
  defina(aes_conf, 'cipher_mode', 'cbc')                                                                                                                                               
  defina(aes_conf, 'iv', '0123456789abcdef')                                                                                                                                           
  plaintext = 'hello aes cbc-256'                                                                                                                                                   
}                                                                                                                                                                                     
if and($http_mode, eq($http_mode, 'ofb-256')) {                                                                                                                                       
  defina(aes_conf, 'key', '146ebcc8-392b-4b3a-a720-e7356f62')                                                                                                                          
  defina(aes_conf, 'cipher_len', 256)                                                                                                                                                  
  defina(aes_conf, 'cipher_mode', 'ofb')                                                                                                                                               
  defina(aes_conf, 'iv', tochar(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0))                                                                                                                      
  plaintext = 'hello aes ofb-256'                                                                                                                                                   
}                                                                                                                                                                                     

aes_obj = aes_new(aes_conf)                                                                                                                                                           
if not(aes_obj) {                                                                                                                                                                     
  say(concat('aes obj failed'))                                                                                                                                                     
  exit(400)                                                                                                                                                                         
}                                                                                                                                                                                     

ciphertext = aes_enc(aes_obj, plaintext)                                                                                                                                              
plaintext_reverse = aes_dec(aes_obj, ciphertext)                                                                                                                                      

say(concat('plain: ', plaintext))                                                                                                                                                     
say(concat('cipher: ', tohex(ciphertext)))                                                                                                                                            
say(concat('plain_reverse: ', plaintext_reverse))                                                                                                                                     

if ne(plaintext, plaintext_reverse) {                                                                                                                                                 
  say('plaintext ~= plaintext_reverse')                                                                                                                                            
  exit(400)                                                                                                                                                                        
}

sha1

Item Descrição
Sintaxe sha1(s)
Recurso Calcula um hash SHA-1.
Parâmetro s: a string para calcular o resumo de hash.
Valor de retorno Retorna um hash SHA-1 em formato binário.
Exemplo
digest = sha1('hello sha')                                                                                                                                                        
say(concat('sha1:', tohex(digest)))
Saída:
sha1:853789bc783a6b573858b6cc9f913afe82962956

sha2

Item Descrição
Sintaxe sha2(s, l)
Recurso Calcula um hash SHA-2.
Parâmetro
  • s: a string para calcular o resumo de hash.
  • l: o comprimento do valor SHA-2. Valores válidos: 224, 256, 384 e 512.
Valor de retorno Retorna um hash SHA-2 em formato binário.
Exemplo
digest = sha2('hello sha2', 224)
say(concat('sha2-224:', tohex(digest)))

digest = sha2('hello sha2', 256)
say(concat('sha2-256:', tohex(digest)))

digest = sha2('hello sha2', 384)
say(concat('sha2-384:', tohex(digest)))

digest = sha2('hello sha2', 512)
say(concat('sha2-512:', tohex(digest)))
Saída:
sha2-224:b24b7effcf53ce815ee7eb73c7382613aba1c334e2a1622655362927
sha2-256:af0425cee23c236b326ed1f008c9c7c143a611859a11e87d66d0a4c3217c7792
sha2-384:bebbdde9efabd4b9cf90856cf30e0b024dd13177d9367d2dcf8d7a04e059f92260f16b21e261358c2271be32086ef35b
sha2-512:a1d1aef051c198c0d26bc03500c177a315fa248cea815e04fbb9a75e5be5061617daab311c5e3d0b215dbfd4e83e73f23081242b0143dcdfce5cd92ec51394f7

hmac

Item Descrição
Sintaxe hmac(k, s, v)
Recurso Calcula um valor HMAC.
Parâmetro
  • k: a chave do algoritmo.
  • s: a string para calcular o resumo de hash.
  • v: a versão do algoritmo. Valores válidos: md5, sha256 e sha512.
Valor de retorno Retorna um valor HMAC em formato binário.
Exemplo
k = '146ebcc8-392b-4b3a-a720-e7356f62f87b'
v = 'hello mac'
say(concat('hmac(md5): ', tohex(hmac(k, v, 'md5'))))
say(concat('hmac(sha1): ', tohex(hmac(k, v, 'sha1'))))
say(concat('hmac(sha256): ', tohex(hmac(k, v, 'sha256'))))
say(concat('hmac(sha512): ', tohex(hmac(k, v, 'sha512'))))
say(concat('hmac_sha1(): ', tohex(hmac_sha1(k, v))))
Saída:
hmac(md5): 358cbfca8ad663b547c83748de2ea778
hmac(sha1): 5555633cef48c3413b68f9330e99357df1cc3d93
hmac(sha256): 7a494543cad3b92ce1e7c4bbc86a8f5212b53e4d661f7830f455847540a85771
hmac(sha512): 59d7c07996ff675b45bd5fd40a6122bb5f40f597357a9b4a9e29da6f5c7cb806798c016fe09cb46457b6df9717d26d0af19896f72eaf4296be03e3681fea59ad
hmac_sha1(): 5555633cef48c3413b68f9330e99357df1cc3d93

hmac_sha1

Item Descrição
Sintaxe hmac_sha1(k, s)
Recurso Calcula um valor HMAC-SHA-1.
Parâmetro
  • s: a string para calcular o resumo de hash.
  • k: a chave HMAC-SHA-1.
Valor de retorno Retorna um valor HMAC-SHA-1 em formato binário.
Exemplo
k = '146ebcc8-392b-4b3a-a720-e7356f62f87b'
v = 'hello mac'
say(concat('hmac(md5): ', tohex(hmac(k, v, 'md5'))))
say(concat('hmac(sha1): ', tohex(hmac(k, v, 'sha1'))))
say(concat('hmac(sha256): ', tohex(hmac(k, v, 'sha256'))))
say(concat('hmac(sha512): ', tohex(hmac(k, v, 'sha512'))))
say(concat('hmac_sha1(): ', tohex(hmac_sha1(k, v))))
Saída:
hmac(md5): 358cbfca8ad663b547c83748de2ea778
hmac(sha1): 5555633cef48c3413b68f9330e99357df1cc3d93
hmac(sha256): 7a494543cad3b92ce1e7c4bbc86a8f5212b53e4d661f7830f455847540a85771
hmac(sha512): 59d7c07996ff675b45bd5fd40a6122bb5f40f597357a9b4a9e29da6f5c7cb806798c016fe09cb46457b6df9717d26d0af19896f72eaf4296be03e3681fea59ad
hmac_sha1(): 5555633cef48c3413b68f9330e99357df1cc3d93

md5

Item Descrição
Sintaxe md5(s)
Recurso Calcula um resumo MD5.
Parâmetro s: a string para calcular o resumo de hash.
Valor de retorno Retorna um valor MD5 em formato hexadecimal.
Exemplo
say(concat('md5: ', md5('hello md5')))
Saída:
md5: 741fc6b1878e208346359af502dd11c5

md5_bin

Item Descrição
Sintaxe md5_bin(s)
Recurso Calcula um resumo MD5.
Parâmetro s: a string para calcular o resumo de hash.
Valor de retorno Retorna um resumo MD5 em formato binário.
Exemplo
say(concat('md5_bin: ', tohex(md5_bin('hello md5'))))
Saída:
md5_bin: 741fc6b1878e208346359af502dd11c5