Erlang返回空二进制文件进行AES加密
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Erlang返回空二进制文件进行AES加密相关的知识,希望对你有一定的参考价值。
Erlang/OTP 22 [erts-10.6.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace]
Eshell V10.6.4 (abort with ^G)
1> application:ensure_all_started(crypto).
{ok,[crypto]}
2> Key = <<1:128>>.
<<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1>>
3> Text = <<"hello crypto">>.
<<"hello crypto">>
4> crypto:crypto_one_time(aes_128_ecb, Key, Text, true).
<<>>
5> Ref = crypto:crypto_init(aes_128_ecb, Key, true).
#Ref<0.3726173343.1880227841.208986>
6> crypto:crypto_update(Ref, Text).
<<>>
我不知道我在做什么错,但是正如您在上面看到的那样,当我尝试加密某些内容时,crypto_one_time和crypto_update都返回一个空二进制。
答案
尝试使用crypto:crypto_one_time/5
:
1> Key = <<1:128>>.
<<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1>>
2> IV = <<0:128>>.
<<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0>>
3> Txt = [<<"First bytes">>,<<"Second bytes">>].
[<<"First bytes">>,<<"Second bytes">>]
4> crypto:crypto_one_time(aes_128_ctr, Key, IV, Txt, true)
<<67,44,216,166,25,130,203,5,66,6,162,16,79,94,115,234, 197,94,253,16,144,151,41>>
以上是关于Erlang返回空二进制文件进行AES加密的主要内容,如果未能解决你的问题,请参考以下文章