Last active
January 12, 2018 21:35
-
-
Save lasseebert/993a2f35f97f5df1d61a4c6e521802f2 to your computer and use it in GitHub Desktop.
Decrypting AES CRT (Counter mode) in Elixir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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