【发布时间】:2018-02-21 00:03:02
【问题描述】:
我正致力于将解密功能从 .NET 移植到 elixir 以作为概念证明。
谁能给我一些指导,看看这是否适用于 Erlang 加密模块?我玩过block_decrypt 函数,但永远无法得到正确的结果。我认为我的问题来自不正确的密钥和 IV。
我不确定如何从加密的纯文本值中导出字节数据以传递给block_decrypt。
这是我用来尝试解密的长生不老药代码:
defmodule TestApp.Decrypt do
@iv <<30,64,180,159,172,197,92,10,197,3,39,75,53,92,93,37>>
def unpad(data) do
to_remove = :binary.last(data)
:binary.part(data, 0, byte_size(data) - to_remove)
end
def decrypt(data, key) do
IO.puts "WOrking to decrypt #{data} using #{key}"
padded = :crypto.block_decrypt(:aes_cbc256, key, @iv, :base64.decode(data))
unpad(padded)
end
end
我尝试传递一个 32 字节的密钥,但出现此错误:
Erlang error: :notsup
加密库指出该错误是因为我的 erlang 构建中未启用脏调度程序,但在我研究之前我不知道我是否朝着正确的方向前进。
【问题讨论】:
-
如果您发布用于加密的代码、未加密和加密文本 (hexdump) 的示例以及您编写的用于解密的代码不起作用会更好。我成功地为一个客户端实现了解密功能,其中数据被 Perl 中的某个加密模块加密,所以只要你的算法是由 Erlang 的
crypto实现的,应该是可以的。 -
@Dogbert,感谢您的意见。我会整理一些东西并更新我的问题。
-
@Dogbert 已编辑问题。
-
在加密文档中它说
May throw exception notsup in case the chosen Type is not supported by the underlying OpenSSL implementation. -
fwiw,如果我删除
unpad:s.ryanwinchester.ca/2W2n0L0H062v,我可以毫无例外地运行它
标签: elixir