<div dir="ltr">John, thanks it's very helpful.</div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-06-20 17:12 GMT+04:00 John Kemp <span dir="ltr"><<a href="mailto:john@jkemp.net" target="_blank">john@jkemp.net</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 06/20/2014 07:00 AM, Alexander Petrovsky wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi!<br>
<br>
I need to encrypt some data with ads_cbc_128, and I do like:<br>
<br>
crypto:aes_cbc_128_encrypt(<<"<u></u>B3E80545C3C9968096E85A7E0A4A57<u></u>79">>,<br>
<<"96E85A7E0A4A5779">>,<br>
<<"id=14&bid=00.004300&<u></u>clickUrl=<a href="http://duckduckgo.com" target="_blank">http://duckduckgo.com</a><u></u>&pid=3101&source=100&search-<u></u>id=42&search-date=00:00:00">>)<u></u>.<br>

** exception error: bad argument<br>
      in function  crypto:aes_cbc_crypt/4<br>
         called as<br>
crypto:aes_cbc_crypt(<<"<u></u>B3E80545C3C9968096E85A7E0A4A57<u></u>79">>,<br>
                                        <<"96E85A7E0A4A5779">>,<br>
<br>
  <<"id=14&bid=00.004300&<u></u>clickUrl=<a href="http://duckduckgo.com" target="_blank">http://duckduckgo.com</a><u></u>&pid=3101&source=100&search-<u></u>id=42&search-date=00:00:00">>,<br>

                                        true)<br>
<br>
seems like the size of data should be the equal the power on 2, and then<br>
I do:<br>
<br>
crypto:aes_cbc_128_encrypt(<<"<u></u>B3E80545C3C9968096E85A7E0A4A57<u></u>79">>,<br>
<<"96E85A7E0A4A5779">>,<br>
<<"id=14&bid=00.004300&<u></u>clickUrl=<a href="http://duckduckgo.com" target="_blank">http://duckduckgo.com</a><u></u>&pid=3101&source=100&search-<u></u>id=42&search-date=00:00:00",<br>

0:24/unit:8>>).<br>
<<87,187,244,217,66,251,202,<u></u>118,238,90,226,245,209,213,<br>
   158,166,203,46,8,30,113,122,<u></u>172,204,163,50,193,34,243,<br>
   ...>><br>
<br>
Is there any way, don't fill the binary by zeros?<br>
</blockquote>
<br></div></div>
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: <a href="http://www.erlang.org/documentation/doc-5.8.3/lib/crypto-2.0.2.1/doc/html/crypto.html#aes_cbc_128_encrypt-3" target="_blank">http://www.erlang.org/<u></u>documentation/doc-5.8.3/lib/<u></u>crypto-2.0.2.1/doc/html/<u></u>crypto.html#aes_cbc_128_<u></u>encrypt-3</a>).<div class="">
<br>
<br>
 How properly I should<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
do this?<br>
</blockquote>
<br>
</div><a href="https://github.com/spawngrid/cowboy_session/blob/master/src/cowboy_session_secure.erl" target="_blank">https://github.com/spawngrid/<u></u>cowboy_session/blob/master/<u></u>src/cowboy_session_secure.erl</a> shows what looks like a good example of how to do the padding more generally than in your example.<br>

<br>
- johnk<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">
<br>
<br>
--<br>
Петровский Александр / Alexander Petrovsky,<br>
<br>
Skype: askjuise<br>
Phone: +7 914 8 820 815<br>
<br>
<br>
<br></div>
______________________________<u></u>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<u></u>listinfo/erlang-questions</a><br>
<br>
</blockquote>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Петровский Александр / Alexander Petrovsky,<br><br>Skype: askjuise<br><div>Phone: +7 914 8 820 815<div><br></div></div></div>
</div>