Софт [Module] Crypto

manoaratefy

Новичок
4
0
I tried to use this library to encrypt and send message to a PHP but it seems not working.

My LUA code:
LUA part - Encrypt the text and output it:
local crypto = require 'crypto_lua'
local base64 = require "base64"
local cjson = require "cjson"

local aes_key = crypto.aes_generate_key()
local aes_iv = crypto.aes_generate_iv()

local encrypted = crypto.aes_encode("test", aes_key, aes_iv)

print(cjson.encode({
    key = aes_key,
    iv = aes_iv,
    encrypted = encrypted
}))

The PHP code:
Код:
// Data copied from the printed output of LUA:
$data = 'kEO2PA==';
$key = base64_decode('zOqFI3qTxXd0qKtUrbXQYg==');
$iv = base64_decode('+QqJzwE+3n2Lq6n2WlcO0g==');

// I presume the encryption is AES-192-CBC, I might be wrong
$output = openssl_decrypt($data, 'aes-192-cbc', $key, 0, $iv);
if ($output === false) {
    echo "Error: " . openssl_error_string();
    exit;
}

echo json_encode([
    'data' => $output,
]);

I'm not sure where I did wrong, the openssl_error_string() says "error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length"

Someone can help me?