Erlang returns 用于 aes 加密的空二进制文件

Erlang returns empty binary for aes encryption

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 都是 return 一个空二进制文件.

使用示例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>> 

使用示例crypto:crypto_one_time/4

1> Key = <<1:128>>. 
<<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1>>
2> Txt = [<<"First bytes">>,<<"Second bytes">>].
[<<"First bytes">>,<<"Second bytes">>]
3> crypto:crypto_one_time(aes_128_ecb, Key,  Txt, true).   
<<231,108,83,104,188,131,182,65,2,128,78,162,210,149,128,248>>