【问题标题】:AES Decryption with key derivation function具有密钥导出功能的 AES 解密
【发布时间】: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,如果我删除unpads.ryanwinchester.ca/2W2n0L0H062v,我可以毫无例外地运行它

标签: elixir


【解决方案1】:

erlang 加密错误不是很有帮助。看起来您可能指定了错误的密码。而不是aes_cbc256,您可能想要aes_256_cbc。见http://erlang.org/doc/man/crypto.html#block_decrypt-4

您可能还想查看我正在开发的一个名为 Apoc 的项目,该项目将这些东西封装成更“类似 Elixir”的 API:https://github.com/coderdan/apoc

到目前为止,它在 GCM 模式下支持 AES,但我很乐意为其他密码做出一些贡献!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-20
    • 1970-01-01
    • 2012-07-20
    • 2015-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多