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)
}
|