[erlang-questions] Crypto AES data block size
Alexander Petrovsky
askjuise@REDACTED
Fri Jun 20 15:37:51 CEST 2014
John, thanks it's very helpful.
2014-06-20 17:12 GMT+04:00 John Kemp <john@REDACTED>:
> On 06/20/2014 07:00 AM, Alexander Petrovsky wrote:
>
>> Hi!
>>
>> I need to encrypt some data with ads_cbc_128, and I do like:
>>
>> crypto:aes_cbc_128_encrypt(<<"B3E80545C3C9968096E85A7E0A4A5779">>,
>> <<"96E85A7E0A4A5779">>,
>> <<"id=14&bid=00.004300&clickUrl=http://duckduckgo.com
>> &pid=3101&source=100&search-id=42&search-date=00:00:00">>).
>> ** exception error: bad argument
>> in function crypto:aes_cbc_crypt/4
>> called as
>> crypto:aes_cbc_crypt(<<"B3E80545C3C9968096E85A7E0A4A5779">>,
>> <<"96E85A7E0A4A5779">>,
>>
>> <<"id=14&bid=00.004300&clickUrl=http://duckduckgo.com
>> &pid=3101&source=100&search-id=42&search-date=00:00:00">>,
>> true)
>>
>> seems like the size of data should be the equal the power on 2, and then
>> I do:
>>
>> crypto:aes_cbc_128_encrypt(<<"B3E80545C3C9968096E85A7E0A4A5779">>,
>> <<"96E85A7E0A4A5779">>,
>> <<"id=14&bid=00.004300&clickUrl=http://duckduckgo.com
>> &pid=3101&source=100&search-id=42&search-date=00:00:00",
>> 0:24/unit:8>>).
>> <<87,187,244,217,66,251,202,118,238,90,226,245,209,213,
>> 158,166,203,46,8,30,113,122,172,204,163,50,193,34,243,
>> ...>>
>>
>> Is there any way, don't fill the binary by zeros?
>>
>
> The crypto:aes_cbc_128_encrypt API requires data be padded to a multiple
> of 16 bytes (as it says in the documentation - for example:
> http://www.erlang.org/documentation/doc-5.8.3/lib/crypto-2.0.2.1/doc/html/
> crypto.html#aes_cbc_128_encrypt-3).
>
>
> How properly I should
>
>> do this?
>>
>
> https://github.com/spawngrid/cowboy_session/blob/master/
> src/cowboy_session_secure.erl shows what looks like a good example of how
> to do the padding more generally than in your example.
>
> - johnk
>
>>
>>
>> --
>> Петровский Александр / Alexander Petrovsky,
>>
>> Skype: askjuise
>> Phone: +7 914 8 820 815
>>
>>
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
--
Петровский Александр / Alexander Petrovsky,
Skype: askjuise
Phone: +7 914 8 820 815
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140620/0dc690f8/attachment.htm>
More information about the erlang-questions
mailing list