From df5be903dfc32e887317a677fa1e0c9eda3ebcaa Mon Sep 17 00:00:00 2001
From: Hans Nilsson
For encryption, set the
See
See
See
See
For encryption, set the
See
See
Part of the
For encryption, set the
See
See
For decryption, set the
See
See
They are not deprecated for now, but may be in a future. +
They are not deprecated for now, but may be in a future release.
@@ -76,7 +76,8 @@In those functions the internal crypto state is first created and initialized - with the cipher type, the key and possibly other data. Then the data is encrypted or decrypted, + with the cipher type, the key and possibly other data. Then the single binary is encrypted + or decrypted, the crypto state is de-allocated and the result of the crypto operation is returned.
The Encrypting two blocks: The functions This example shows first the encryption of two blocks and then decryptions of the cipher
+ text, but divided into three blocks just to show that it is possible to divide the plain text and
+ cipher text differently for some ciphers: Note that the internal data that the The same example as in the
The The same example as in the
+ The
1> crypto:start().
ok
2> Key = <<1:128>>.
- 2> IV = <<0:128>>.
- 2> StateEnc = crypto:crypto_init(aes_128_ctr, Key, IV, true). % encrypt -> true
+ <<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1>>
+ 3> IV = <<0:128>>.
+ <<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0>>
+ 4> StateEnc = crypto:crypto_init(aes_128_ctr, Key, IV, true). % encrypt -> true
#Ref<0.3768901617.1128660993.124047>
- 3> crypto:crypto_update(StateEnc, <<"First bytes">>).
+ 5> crypto:crypto_update(StateEnc, <<"First bytes">>).
<<67,44,216,166,25,130,203,5,66,6,162>>
- 4> crypto:crypto_update(StateEnc, <<"Second bytes">>).
+ 6> crypto:crypto_update(StateEnc, <<"Second bytes">>).
<<16,79,94,115,234,197,94,253,16,144,151,41>>
- 5>
- 5> StateDec = crypto:crypto_init(aes_128_ctr, Key, IV, false). % decrypt -> false
+ 7>
+ 7> StateDec = crypto:crypto_init(aes_128_ctr, Key, IV, false). % decrypt -> false
#Ref<0.3768901617.1128660994.124255>
- 6> crypto:crypto_update(StateDec, <<67,44,216,166,25,130,203>>).
+ 8> crypto:crypto_update(StateDec, <<67,44,216,166,25,130,203>>).
<<"First b">>
- 7> crypto:crypto_update(StateDec, <<5,66,6,162,16,79,94,115,234,197,
- 94,253,16,144,151>>).
+ 9> crypto:crypto_update(StateDec, <<5,66,6,162,16,79,94,115,234,197,
+ 94,253,16,144,151>>).
<<"ytesSecond byte">>
- 8> crypto:crypto_update(StateDec, <<41>>).
+ 10> crypto:crypto_update(StateDec, <<41>>).
<<"s">>
- 9>
+ 11>
- 2> Key = <<1:128>>.
+ 1> Key = <<1:128>>.
+ <<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1>>
2> IV = <<0:128>>.
- 2> Txt = [<<"First bytes">>,<<"Second bytes">>],
- 2> crypto:crypto_one_time(aes_128_ctr, Key, IV, Txt, true).
+ <<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>>
- 3>
+ 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> AAD = <<"Some bytes">>.
+ <<"Some bytes">>
+ 5> crypto:crypto_one_time_aead(aes_128_gcm, Key, IV, Txt, AAD, true).
+ {<<240,130,38,96,130,241,189,52,3,190,179,213,132,1,72,
+ 192,103,176,90,104,15,71,158>>,
+ <<131,47,45,91,142,85,9,244,21,141,214,71,31,135,2,155>>}
+ 9>
+
+