简体   繁体   English

在 PHP 中加密大量数据

[英]Crypt large amount of data in PHP

I develop a software which have to crypt data before to send it to another instance of the same soft (which have to decrypt it of course).我开发了一个软件,它必须先加密数据才能将其发送到同一软件的另一个实例(当然必须解密它)。 I first use openssl_public_encrypt / openssl_private_decrypt, like that我首先使用openssl_public_encrypt / openssl_private_decrypt,像这样

foreach(str_split($sData, MAXSIZE) as $sChunk)
{
    if( ! @openssl_public_encrypt($sChunk, $crypted, $sPublicKey)) throw new Exception('openssl_public_encrypt');
    $aCrypted[] = $crypted;
}

and

$sResult = '';
foreach($aCrypted['data'] as $ct => $sChunkCrypted)
{
    if( ! openssl_private_decrypt($sChunkCrypted, $sChunk, $sPrivateKey)) throw new Exception("decrypt");
    $sResult .= $sChunk;
}

because the chunk of data to encrypt can't be larger than the key, but the decrypt part take too much time (xdebug tells me this is calls to openssl_private_decrypt() which take all the time).因为要加密的数据块不能大于密钥,但解密部分需要太多时间(xdebug 告诉我这是对 openssl_private_decrypt() 的调用,这需要所有时间)。

I try with symmetric algorithms mcrypt_decrypt/MCRYPT_RIJNDAEL_256 (with openssl to crypt the key) but it's worse.我尝试使用对称算法 mcrypt_decrypt/MCRYPT_RIJNDAEL_256 (使用 openssl 加密密钥),但情况更糟。 What can I do to transfert large amount of data in a secure way?如何以安全的方式传输大量数据? Files are CSV (text) and are put on a SSH/SFTP server, they have to be crypted.文件是 CSV(文本)并放在 SSH/SFTP 服务器上,它们必须加密。

Thanks,谢谢,
Cédric塞德里克

Just use SCP or SFTP.只需使用 SCP 或 SFTP。 They'll use SSL for the actual data transmission, so you'll get the encryption stuff automatically.他们将使用 SSL 进行实际数据传输,因此您将自动获得加密内容。 If you need to STORE the files in a crypted state, then you'll have to use mcrypt and its friends to do the encryption for you.如果您需要将文件存储在加密的 state 中,那么您必须使用 mcrypt 及其朋友为您进行加密。

As for the "data has to be smaller than the key" only applies in a one-time-pad situation.至于“数据必须小于密钥”仅适用于一次性填充的情况。 Modern ciphers essentially always have keys that are smaller than the data being encrypted.... think of a large RAR or ZIP file - multi-megabytes of data, but a key (password) that's only a few characters in size.现代密码本质上总是具有小于被加密数据的密钥……想想大型 RAR 或 ZIP 文件 - 数兆字节的数据,但密钥(密码)只有几个字符大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM