【发布时间】:2020-03-19 21:34:59
【问题描述】:
我想使用 mergAESEncryptWithKey pData,pKey,pIV,[pMode],[pKeySize],[pPadding] 加密实时代码中的数据。然后将加密的数据发布到 php。 PhP 使用相同的函数解密数据,对数据进行处理,然后加密结果并将其发布到 livecode。 Livecode 然后从 php 解密数据
我的 PHP 代码看起来像这样(这很完美)
function encrypt($plaintext, $salt) {
$method = "AES-256-CBC";
$key = hash('sha256', $salt, true);
$iv = openssl_random_pseudo_bytes(32);
$ciphertext = openssl_encrypt($plaintext, $method, $key, $iv);
$hash = hash_hmac('sha256', $ciphertext . $iv, $key, true);
return $iv . $hash . $ciphertext;
}
function decrypt($ivHashCiphertext, $salt) {
$method = "AES-256-CBC";
$iv = substr($ivHashCiphertext, 0, 32);
$hash = substr($ivHashCiphertext, 32, 48);
$ciphertext = substr($ivHashCiphertext, 64);
$key = hash('sha256', $salt, true);
//if (!hash_equals(hash_hmac('sha256', $ciphertext . $iv, $key, true), $hash)) return null;
return openssl_decrypt($ciphertext, $method, $key, $iv);
}
echo $encrypted."</br>";
echo "----------------------------The message is:<br/>";
echo decrypt($encrypted, 'hashsalt');
【问题讨论】:
-
这里有问题吗?
-
是的!我如何在 livecode 中做同样的事情?
-
你应该先试试。只需在按钮中创建一个 mouseUp 处理程序,看看你能走多远。如果您已经认真尝试过,但几个小时后仍然无法弄清楚,请回到这里,发布您的代码,我们会尽力提供帮助。同时,你能解释一下你为什么需要这个吗?也许有更简单更好的解决方案。