有什么方法可以安全地将字符串从 Elixir 发送到 PHP 吗?(无 SSL)
Is there any way to send a string from Elixir to PHP securely?(no SSL)
我想通过 URL 查询字符串(如:?secure_string=xxxxx)将字符串从 Elixir/Phoenix(服务器)安全地发送到 PHP(客户端) .这些环境没有 SSL,但它们可以提前共享私钥。所以我想我可以通过加密安全地传输字符串,例如 AES。
由于PHP有openssl_decrypt(),它可以像下面这样解密字符串。 Elixir(或 Erlang?)可以调用 openssl_encrypt,而不是 System.cmd("/usr/bin/openssl")?还有其他(更好的)方法吗?
$key = 'private_key_string_shared_both';
$algorithm = 'AES-128-ECB'
$decrypt = openssl_decrypt($encrypt_string, $algorithm, $key);
您可以使用 :crypto
application。它是一个 Erlang 应用程序,能够使用不同的密码进行加密和解密。
:crypto.block_decrypt(:aes_ecb, key, data)
密钥和数据的字节数都必须能被 16 整除。它们可以是二进制文件 "like this"
或 iolists 'like this'
。工作示例是:
iex(1)> key = List.duplicate(100, 16)
'dddddddddddddddd'
iex(2)> string = List.duplicate(101, 16)
'eeeeeeeeeeeeeeee'
:crypto.block_encrypt(:aes_ecb, key, string)
<<6, 190, 103, 115, 142, 170, 75, 103, 128, 93, 168, 196, 108, 253, 41, 27>>
我想通过 URL 查询字符串(如:?secure_string=xxxxx)将字符串从 Elixir/Phoenix(服务器)安全地发送到 PHP(客户端) .这些环境没有 SSL,但它们可以提前共享私钥。所以我想我可以通过加密安全地传输字符串,例如 AES。
由于PHP有openssl_decrypt(),它可以像下面这样解密字符串。 Elixir(或 Erlang?)可以调用 openssl_encrypt,而不是 System.cmd("/usr/bin/openssl")?还有其他(更好的)方法吗?
$key = 'private_key_string_shared_both';
$algorithm = 'AES-128-ECB'
$decrypt = openssl_decrypt($encrypt_string, $algorithm, $key);
您可以使用 :crypto
application。它是一个 Erlang 应用程序,能够使用不同的密码进行加密和解密。
:crypto.block_decrypt(:aes_ecb, key, data)
密钥和数据的字节数都必须能被 16 整除。它们可以是二进制文件 "like this"
或 iolists 'like this'
。工作示例是:
iex(1)> key = List.duplicate(100, 16)
'dddddddddddddddd'
iex(2)> string = List.duplicate(101, 16)
'eeeeeeeeeeeeeeee'
:crypto.block_encrypt(:aes_ecb, key, string)
<<6, 190, 103, 115, 142, 170, 75, 103, 128, 93, 168, 196, 108, 253, 41, 27>>