Re: aes-128-cbc decryption in erlang

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: aes-128-cbc decryption in erlang

Max Treskin
Hello

What is erlang crypto analog of following comand?

openssl enc -d -aes-128-cbc -pass env:KEY -in file.ssl -out file.txt

There is function aes_cbc_128_decrypt which takes Key, IVec and
encoded data, but how I can get an IVec?
crypto:aes_cbc_ivec returns some IVec, but when it passed to
aes_cbc_128_decrypt I have wrong output of decoded data. May be I
doing something wrong?

--
Maxim Treskin

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: aes-128-cbc decryption in erlang

Kenji Rikitake
The first value of IV must be given before the decryption starts.  The
man entry of "openssl enc" says the first IV will be given from the
password. See the -iv option of OpenSSL.

And the aes_cbc_ivec usage example is available in
lib/ssh/src/ssh_transport.erl

Regards,
Kenji Rikitake

In the message <[hidden email]>
dated Fri, Feb 19, 2010 at 10:22:36PM +0600,
Maxim Treskin <[hidden email]> writes:
> What is erlang crypto analog of following comand?
>
> openssl enc -d -aes-128-cbc -pass env:KEY -in file.ssl -out file.txt
>
> There is function aes_cbc_128_decrypt which takes Key, IVec and
> encoded data, but how I can get an IVec?
> crypto:aes_cbc_ivec returns some IVec, but when it passed to
> aes_cbc_128_decrypt I have wrong output of decoded data. May be I
> doing something wrong?

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: aes-128-cbc decryption in erlang

Vance Shipley
In reply to this post by Max Treskin
Maxim,

For an example of it's use you could look at the milenage
module from the 3Gdb HSS project:

        http://www.3gdb.org/doc/
   http://code.google.com/p/hss/source/browse/trunk/src/milenage.erl

--
        -Vance

On Fri, Feb 19, 2010 at 10:23:00PM +0600, Maxim Treskin wrote:
}  There is function aes_cbc_128_decrypt which takes Key, IVec and
}  encoded data, but how I can get an IVec?

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: aes-128-cbc decryption in erlang

Max Treskin
Hello

I wrote function which encodes/decodes arbitrary text using specified
Key and IVec:


aes_dec() ->
    Key = <<"ABCDEFGHIJKLMNOPQRSTUVWXYZ123456">>,
    IVec = <<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0>>,
    Text = <<"gdfgertehgrfcnyeyuyrfghhhhhdtest">>,
    Enc = crypto:aes_cbc_128_encrypt(Key, IVec, Text),
    Res = crypto:aes_cbc_128_decrypt(Key, IVec, Enc),
    io:format("Res: ~s~n", [binary_to_list(Res)]).


Result of function is:

1> cr_util:aes_dec().
ïQRSTUVWXYZ123456gdfgertehgrfcnyeyuyrfghhhhhdtest
ok

It is really unexpected for me. Can you help me?

Thank you

On 20 February 2010 05:39, Vance Shipley <[hidden email]> wrote:

> Maxim,
>
> For an example of it's use you could look at the milenage
> module from the 3Gdb HSS project:
>
>        http://www.3gdb.org/doc/
>   http://code.google.com/p/hss/source/browse/trunk/src/milenage.erl
>
> --
>        -Vance
>
> On Fri, Feb 19, 2010 at 10:23:00PM +0600, Maxim Treskin wrote:
> }  There is function aes_cbc_128_decrypt which takes Key, IVec and
> }  encoded data, but how I can get an IVec?
>



--
Maxim Treskin

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: aes-128-cbc decryption in erlang

Kenji Rikitake
For aes_cbc_128_*/3 functions, The length of Key must be 128 bits.
The Key below has 32 bytes aka 256 bits.

Kenji Rikitake

In the message <[hidden email]>
dated Sat, Feb 20, 2010 at 11:33:34PM +0600,
Maxim Treskin <[hidden email]> writes:
> aes_dec() ->
>     Key = <<"ABCDEFGHIJKLMNOPQRSTUVWXYZ123456">>,
>     IVec = <<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0>>,
>     Text = <<"gdfgertehgrfcnyeyuyrfghhhhhdtest">>,
>     Enc = crypto:aes_cbc_128_encrypt(Key, IVec, Text),
>     Res = crypto:aes_cbc_128_decrypt(Key, IVec, Enc),
>     io:format("Res: ~s~n", [binary_to_list(Res)]).


________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: aes-128-cbc decryption in erlang

Richard Andrews-5
In reply to this post by Max Treskin
On Sun, Feb 21, 2010 at 4:33 AM, Maxim Treskin <[hidden email]> wrote:
> aes_dec() ->
>    Key = <<"ABCDEFGHIJKLMNOPQRSTUVWXYZ123456">>,
>    IVec = <<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0>>,
>    Text = <<"gdfgertehgrfcnyeyuyrfghhhhhdtest">>,
>    Enc = crypto:aes_cbc_128_encrypt(Key, IVec, Text),
>    Res = crypto:aes_cbc_128_decrypt(Key, IVec, Enc),
>    io:format("Res: ~s~n", [binary_to_list(Res)]).
...
> 1> cr_util:aes_dec().
> ïQRSTUVWXYZ123456gdfgertehgrfcnyeyuyrfghhhhhdtest
> ok
>
> It is really unexpected for me. Can you help me?

Maybe for a 128-bit cipher you should use a 128-bit key.

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]