Php Livecode mergAESEncryptWithKey函数
我想使用mergAESEncryptWithKey pData、pKey、pIV、[pMode]、[pKeySize]、[pPadding]对livecode中的数据进行加密。然后将加密的数据发布到php。PhP使用相同的函数解密数据,对数据做一些处理,然后加密结果并将其发布到livecode。Livecode然后从php解密数据 我的PHP代码看起来是这样的(这很好用)Php Livecode mergAESEncryptWithKey函数,php,livecode,Php,Livecode,我想使用mergAESEncryptWithKey pData、pKey、pIV、[pMode]、[pKeySize]、[pPadding]对livecode中的数据进行加密。然后将加密的数据发布到php。PhP使用相同的函数解密数据,对数据做一些处理,然后加密结果并将其发布到livecode。Livecode然后从php解密数据 我的PHP代码看起来是这样的(这很好用) 函数加密($plaintext,$salt){ $method=“AES-256-CBC”; $key=hash('sha2
函数加密($plaintext,$salt){
$method=“AES-256-CBC”;
$key=hash('sha256',$salt,true);
$iv=openssl_随机_伪_字节(32);
$ciphertext=openssl\u encrypt($plaintext、$method、$key、$iv);
$hash=hash_hmac('sha256',$ciphertext.$iv,$key,true);
返回$iv.$hash.$ciphertext;
}
函数解密($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);
//如果(!hash_等于(hash_hmac('sha256',$ciphertext.$iv,$key,true),$hash))返回null;
返回openssl_decrypt($ciphertext,$method,$key,$iv);
}
echo$已加密。“”;
echo“-----------------------------消息是:
”;
回声解密($encrypted,'hashsalt');
对于大多数不知道但仍想发布无用评论的人来说,我已经找到了答案@Sammitch和@Mark问问题并不意味着某人愚蠢
/*
* Encrypt or decrypt data using
* AES-256-CBC
*/
function encrypt_decrypt($mode,$data,$key,$salt){
//define the cipher method
$ciphering = "AES-256-CBC";
// Use OpenSSl Encryption method. This works on PHP 7.2 and above
$iv_length = openssl_cipher_iv_length($ciphering);
$options = 0;
if($mode=="encrypt"){
// Use openssl_encrypt() function to encrypt the data
$Data = openssl_encrypt($data, $ciphering, $key, $options, $salt);
}else{
// Use openssl_decrypt() function to decrypt the data
$Data = openssl_decrypt($data, $ciphering, $key,$options, $salt);
}
return $Data;
}
哦,这是写给livecode的
//encrypt
encrypt tString using "aes-256-cbc" with key theKey and IV saltHash at 256 bit
//decrypt
decrypt base64Decode(varEnc) using "aes-256-cbc" with key theKey and IV saltHash at 256 bit
这里有什么问题吗?是的!!!如何在livecode中实现同样的功能?您应该先尝试一下。只要在按钮上做一个鼠标处理程序,看看你能走多远。如果您已经认真尝试过了,但几个小时后仍然无法解决,请回到这里,发布您的代码,我们将尽力提供帮助。同时,你能解释一下你为什么需要这个吗?也许有一个更简单更好的解决方案。您想使用mergAESEncryptWithKey函数。您还没有回答自己的问题:-)
//encrypt
encrypt tString using "aes-256-cbc" with key theKey and IV saltHash at 256 bit
//decrypt
decrypt base64Decode(varEnc) using "aes-256-cbc" with key theKey and IV saltHash at 256 bit