Skip to content

Instantly share code, notes, and snippets.

@lasseebert
Last active January 12, 2018 21:35
Show Gist options
  • Save lasseebert/993a2f35f97f5df1d61a4c6e521802f2 to your computer and use it in GitHub Desktop.
Save lasseebert/993a2f35f97f5df1d61a4c6e521802f2 to your computer and use it in GitHub Desktop.
Decrypting AES CRT (Counter mode) in Elixir
defmodule DecryptPayload do
@moduledoc """
Decrypts payload
"""
def run(payload_hex, key_hex, iv_hex) do
payload_bytes = payload_hex |> Base.decode16!
key_bytes = key_hex |> Base.decode16!
iv_bytes = iv_hex |> Base.decode16!
state = :crypto.stream_init(:aes_ctr, key_bytes, iv_bytes)
{_new_state, decrypted} = :crypto.stream_decrypt(state, payload_bytes)
decrypted
|> Base.encode16
|> IO.inspect
end
end
[payload_hex, key_hex, iv_hex] = System.argv
DecryptPayload.run(payload_hex, key_hex, iv_hex)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment