如何使用des_ede3作为加密模式为elixir / erlang block_encrypt / 4函数设置24字节长的密钥 [英] How to set a 24 byte length key to elixir/erlang block_encrypt/4 function using des_ede3 as mode of encryption
问题描述
我试图将数据发送到期望使用3DES加密的外部api,但是在理解如何将 api密钥 作为密钥传递时遇到问题字段到erlangs des_ede3 密码。
Am trying to send data to an external api that expects encrypted data using 3DES encryption but am having issues understanding how to pass my api key as the key field to erlangs des_ede3 cipher.
根据erlangs cipher文档 des_ede3 需要3个密钥,它们的长度均为8个字节。我如何将我的24字节api密钥作为elixir / erlang的密钥传递:cryptoblock_encrypt / 4函数
According to erlangs cipher docs des_ede3 expects 3 keys that are all 8 bytes in length. How can i pass my 24 byte api key as the key to elixir/erlang :cryptoblock_encrypt/4 function
*** how can i pass key to block_encrypt/4 ***
key = "123456789012345678901234"
data = "hello world! The world is yours"
block_size = 8
cipher = :crypto.block_encrypt(:des_ede3, [key, key, key], iv, pad(data, block_size))
如何将我的24字节api密钥作为erlangs block_encrypt / 4的密钥传递,以便我将数据传递到外部api。
How do i pass my 24 byte api key as the key to erlangs block_encrypt/4 in order for me to pass data to the external api.
谢谢
推荐答案
使用二进制模式匹配:
<<k1 :: binary-size(8),
k2 :: binary-size(8),
k3 :: binary-size(8)>> = "123456789012345678901234"
#⇒ "123456789012345678901234"
{k1, k2, k3}
#⇒ {"12345678", "90123456", "78901234"}
这篇关于如何使用des_ede3作为加密模式为elixir / erlang block_encrypt / 4函数设置24字节长的密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!