You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by drmike01 <ms...@gmail.com> on 2012/06/20 22:35:41 UTC

Size of encrypted text?

Quick question (hopefully). I'm planning on using the crypto modules to
encrypt some fields in my database (MySQL) using AES-256.  My understanding
of doing this for standard Java crypto is that it encrypts in 16-byte
blocks, and so the total length of it should be, at most, the next multiple
of 16 longer than the actual data (I think it may actually be slightly
shorter than that, but that doesn't really matter to me). It also should be
stored as some BINARY or BLOB type.

My question is whether or not the same rules apply for Shiro.  The JavaDoc
doesn't mention it, although it makes sense that it would because it's
making the same sort of changes to the underlying data.

Thanks in advance!

--
View this message in context: http://shiro-user.582556.n2.nabble.com/Size-of-encrypted-text-tp7577530.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Size of encrypted text?

Posted by Les Hazlewood <lh...@apache.org>.
At an eyeball scan, it looks to be about (on average) 1/4 to 1/3 of a
millisecond.  That's quite fast!

Thanks again for sharing,

--
Les Hazlewood | @lhazlewood
CTO, Stormpath | http://stormpath.com | @goStormpath | 888.391.5282
Stormpath wins GigaOM Structure Launchpad Award! http://bit.ly/MvZkMk


On Thu, Jun 28, 2012 at 8:11 AM, drmike01 <ms...@gmail.com> wrote:
> Good idea, here's what that looks like (nanoTime()):
>
> +---------+----------+----------+----------+
> | in_size | out_size | enc_time | dec_time |
> +---------+----------+----------+----------+
> |       0 |       44 | 35097000 |   350000 |
> |       1 |       44 |   351000 |   262000 |
> |       2 |       44 |   311000 |   255000 |
> |       3 |       44 |   309000 |   254000 |
> |       4 |       44 |   308000 |   264000 |
> |       5 |       44 |   312000 |   270000 |
> |       6 |       44 |   299000 |   296000 |
> |       7 |       44 |   295000 |   670000 |
> |       8 |       44 |   356000 |   257000 |
> |       9 |       44 |   343000 |   257000 |
> |      10 |       44 |   352000 |   287000 |
> |      11 |       44 |   321000 |   353000 |
> |      12 |       44 |   303000 |   258000 |
> |      13 |       44 |   305000 |   257000 |
> |      14 |       44 |   326000 |   258000 |
> |      15 |       44 |   687000 |   268000 |
> |      16 |       64 |   353000 |   330000 |
> |      17 |       64 |   309000 |   261000 |
> |      18 |       64 |   300000 |   260000 |
> |      19 |       64 |   305000 |   269000 |
> |      20 |       64 |   318000 |   261000 |
> |      21 |       64 |   315000 |   261000 |
> |      22 |       64 |   348000 |   280000 |
> |      23 |       64 |   320000 |   253000 |
> |      24 |       64 |   284000 |   264000 |
> |      25 |       64 |   283000 |   249000 |
> |      26 |       64 |   282000 |   248000 |
> |      27 |       64 |   285000 |   260000 |
> |      28 |       64 |   425000 |   285000 |
> |      29 |       64 |   298000 |   266000 |
> |      30 |       64 |   289000 |   253000 |
> |      31 |       64 |   339000 |   264000 |
> |      32 |       88 |   484000 |   405000 |
> |      33 |       88 |   447000 |   397000 |
> |      34 |       88 |   459000 |   378000 |
> |      35 |       88 |   310000 |   275000 |
> |      36 |       88 |   303000 |   275000 |
> |      37 |       88 |   296000 |   268000 |
> |      38 |       88 |   312000 |   259000 |
> |      39 |       88 |   316000 |   259000 |
> |      40 |       88 |   292000 |   255000 |
> |      41 |       88 |   306000 |   256000 |
> |      42 |       88 |   299000 |   257000 |
> |      43 |       88 |   298000 |   280000 |
> |      44 |       88 |   288000 |   262000 |
> |      45 |       88 |   320000 |   321000 |
> |      46 |       88 |   330000 |   300000 |
> |      47 |       88 |   289000 |   266000 |
> |      48 |      108 |   317000 |   282000 |
> |      49 |      108 |   324000 |   285000 |
> |      50 |      108 |   331000 |   299000 |
> |      51 |      108 |   447000 |   303000 |
> |      52 |      108 |   329000 |   267000 |
> |      53 |      108 |   307000 |   265000 |
> |      54 |      108 |   293000 |  6116000 |
> |      55 |      108 |   506000 |   381000 |
> |      56 |      108 |   421000 |   350000 |
> |      57 |      108 |   326000 |   241000 |
> |      58 |      108 |   424000 |   349000 |
> |      59 |      108 |   448000 |   357000 |
> |      60 |      108 |   448000 |   397000 |
> |      61 |      108 |   456000 |   410000 |
> |      62 |      108 |   336000 |   264000 |
> |      63 |      108 |   412000 |   343000 |
> |      64 |      128 |   424000 |   366000 |
> |      65 |      128 |   394000 |   361000 |
> |      66 |      128 |   411000 |   291000 |
> |      67 |      128 |   330000 |   235000 |
> |      68 |      128 |   278000 |   234000 |
> |      69 |      128 |   262000 |   241000 |
> |      70 |      128 |   254000 |   220000 |
> |      71 |      128 |   283000 |   247000 |
> |      72 |      128 |   271000 |   220000 |
> |      73 |      128 |   265000 |   220000 |
> |      74 |      128 |   279000 |   220000 |
> |      75 |      128 |   268000 |   217000 |
> |      76 |      128 |   320000 |   247000 |
> |      77 |      128 |   282000 |   220000 |
> |      78 |      128 |   286000 |   242000 |
> |      79 |      128 |   322000 |   298000 |
> |      80 |      152 |   273000 |   240000 |
> |      81 |      152 |   288000 |   241000 |
> |      82 |      152 |   272000 |   224000 |
> |      83 |      152 |   264000 |   228000 |
> |      84 |      152 |   421000 |   386000 |
> |      85 |      152 |   473000 |   384000 |
> |      86 |      152 |   285000 |   225000 |
> |      87 |      152 |   286000 |   227000 |
> |      88 |      152 |   287000 |   224000 |
> |      89 |      152 |   285000 |   225000 |
> |      90 |      152 |   274000 |   249000 |
> |      91 |      152 |   275000 |   241000 |
> |      92 |      152 |   377000 |   346000 |
> |      93 |      152 |   267000 |   228000 |
> |      94 |      152 |   280000 |   238000 |
> |      95 |      152 |   269000 |   232000 |
> |      96 |      172 |   380000 |   336000 |
> |      97 |      172 |   275000 |   230000 |
> |      98 |      172 |   268000 |   228000 |
> |      99 |      172 |   282000 |   227000 |
>
> --
> View this message in context: http://shiro-user.582556.n2.nabble.com/Size-of-encrypted-text-tp7577530p7577556.html
> Sent from the Shiro User mailing list archive at Nabble.com.

Re: Size of encrypted text?

Posted by drmike01 <ms...@gmail.com>.
Good idea, here's what that looks like (nanoTime()):

+---------+----------+----------+----------+
| in_size | out_size | enc_time | dec_time |
+---------+----------+----------+----------+
|       0 |       44 | 35097000 |   350000 | 
|       1 |       44 |   351000 |   262000 | 
|       2 |       44 |   311000 |   255000 | 
|       3 |       44 |   309000 |   254000 | 
|       4 |       44 |   308000 |   264000 | 
|       5 |       44 |   312000 |   270000 | 
|       6 |       44 |   299000 |   296000 | 
|       7 |       44 |   295000 |   670000 | 
|       8 |       44 |   356000 |   257000 | 
|       9 |       44 |   343000 |   257000 | 
|      10 |       44 |   352000 |   287000 | 
|      11 |       44 |   321000 |   353000 | 
|      12 |       44 |   303000 |   258000 | 
|      13 |       44 |   305000 |   257000 | 
|      14 |       44 |   326000 |   258000 | 
|      15 |       44 |   687000 |   268000 | 
|      16 |       64 |   353000 |   330000 | 
|      17 |       64 |   309000 |   261000 | 
|      18 |       64 |   300000 |   260000 | 
|      19 |       64 |   305000 |   269000 | 
|      20 |       64 |   318000 |   261000 | 
|      21 |       64 |   315000 |   261000 | 
|      22 |       64 |   348000 |   280000 | 
|      23 |       64 |   320000 |   253000 | 
|      24 |       64 |   284000 |   264000 | 
|      25 |       64 |   283000 |   249000 | 
|      26 |       64 |   282000 |   248000 | 
|      27 |       64 |   285000 |   260000 | 
|      28 |       64 |   425000 |   285000 | 
|      29 |       64 |   298000 |   266000 | 
|      30 |       64 |   289000 |   253000 | 
|      31 |       64 |   339000 |   264000 | 
|      32 |       88 |   484000 |   405000 | 
|      33 |       88 |   447000 |   397000 | 
|      34 |       88 |   459000 |   378000 | 
|      35 |       88 |   310000 |   275000 | 
|      36 |       88 |   303000 |   275000 | 
|      37 |       88 |   296000 |   268000 | 
|      38 |       88 |   312000 |   259000 | 
|      39 |       88 |   316000 |   259000 | 
|      40 |       88 |   292000 |   255000 | 
|      41 |       88 |   306000 |   256000 | 
|      42 |       88 |   299000 |   257000 | 
|      43 |       88 |   298000 |   280000 | 
|      44 |       88 |   288000 |   262000 | 
|      45 |       88 |   320000 |   321000 | 
|      46 |       88 |   330000 |   300000 | 
|      47 |       88 |   289000 |   266000 | 
|      48 |      108 |   317000 |   282000 | 
|      49 |      108 |   324000 |   285000 | 
|      50 |      108 |   331000 |   299000 | 
|      51 |      108 |   447000 |   303000 | 
|      52 |      108 |   329000 |   267000 | 
|      53 |      108 |   307000 |   265000 | 
|      54 |      108 |   293000 |  6116000 | 
|      55 |      108 |   506000 |   381000 | 
|      56 |      108 |   421000 |   350000 | 
|      57 |      108 |   326000 |   241000 | 
|      58 |      108 |   424000 |   349000 | 
|      59 |      108 |   448000 |   357000 | 
|      60 |      108 |   448000 |   397000 | 
|      61 |      108 |   456000 |   410000 | 
|      62 |      108 |   336000 |   264000 | 
|      63 |      108 |   412000 |   343000 | 
|      64 |      128 |   424000 |   366000 | 
|      65 |      128 |   394000 |   361000 | 
|      66 |      128 |   411000 |   291000 | 
|      67 |      128 |   330000 |   235000 | 
|      68 |      128 |   278000 |   234000 | 
|      69 |      128 |   262000 |   241000 | 
|      70 |      128 |   254000 |   220000 | 
|      71 |      128 |   283000 |   247000 | 
|      72 |      128 |   271000 |   220000 | 
|      73 |      128 |   265000 |   220000 | 
|      74 |      128 |   279000 |   220000 | 
|      75 |      128 |   268000 |   217000 | 
|      76 |      128 |   320000 |   247000 | 
|      77 |      128 |   282000 |   220000 | 
|      78 |      128 |   286000 |   242000 | 
|      79 |      128 |   322000 |   298000 | 
|      80 |      152 |   273000 |   240000 | 
|      81 |      152 |   288000 |   241000 | 
|      82 |      152 |   272000 |   224000 | 
|      83 |      152 |   264000 |   228000 | 
|      84 |      152 |   421000 |   386000 | 
|      85 |      152 |   473000 |   384000 | 
|      86 |      152 |   285000 |   225000 | 
|      87 |      152 |   286000 |   227000 | 
|      88 |      152 |   287000 |   224000 | 
|      89 |      152 |   285000 |   225000 | 
|      90 |      152 |   274000 |   249000 | 
|      91 |      152 |   275000 |   241000 | 
|      92 |      152 |   377000 |   346000 | 
|      93 |      152 |   267000 |   228000 | 
|      94 |      152 |   280000 |   238000 | 
|      95 |      152 |   269000 |   232000 | 
|      96 |      172 |   380000 |   336000 | 
|      97 |      172 |   275000 |   230000 | 
|      98 |      172 |   268000 |   228000 | 
|      99 |      172 |   282000 |   227000 |

--
View this message in context: http://shiro-user.582556.n2.nabble.com/Size-of-encrypted-text-tp7577530p7577556.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Size of encrypted text?

Posted by Les Hazlewood <lh...@apache.org>.
P.S.  Another neat timing test would be to use System.nanoTime() as
your start/stop timestamp markers to get nanosecond values since a
single millisecond does not appear to be granular enough.

Cheers,

--
Les Hazlewood
Stormpath Wins GigaOm's Structure LaunchPad Award! http://bit.ly/MvZkMk

On Wed, Jun 27, 2012 at 5:37 PM, Les Hazlewood <lh...@apache.org> wrote:
> Thanks for sharing this!  It is good to have some concrete numbers to
> get a feeling for performance.
>
> Thanks!
>
> --
> Les Hazlewood
> CTO, Stormpath | @goStormpath
> Stormpath Wins GigaOm's Structure LaunchPad Award! http://bit.ly/MvZkMk
>
> On Wed, Jun 27, 2012 at 11:31 AM, drmike01 <ms...@gmail.com> wrote:
>>
>> This is the same data, except column two is the size of it from the
>> toBase64() method, so a bit bigger but not really any slower.
>>
>>       0 |       44 |       10 |        0 |
>> |       1 |       44 |        0 |        1 |
>> |       2 |       44 |        0 |        0 |
>> |       3 |       44 |        0 |        0 |
>> |       4 |       44 |        0 |        0 |
>> |       5 |       44 |        1 |        0 |
>> |       6 |       44 |        1 |        0 |
>> |       7 |       44 |        1 |        0 |
>> |       8 |       44 |        0 |        0 |
>> |       9 |       44 |        0 |        0 |
>> |      10 |       44 |        1 |        0 |
>> |      11 |       44 |        1 |        0 |
>> |      12 |       44 |        0 |        1 |
>> |      13 |       44 |        0 |        1 |
>> |      14 |       44 |        0 |        0 |
>> |      15 |       44 |        0 |        1 |
>> |      16 |       64 |        0 |        1 |
>> |      17 |       64 |        0 |        1 |
>> |      18 |       64 |        0 |        1 |
>> |      19 |       64 |        0 |        0 |
>> |      20 |       64 |        0 |        0 |
>> |      21 |       64 |        0 |        0 |
>> |      22 |       64 |        0 |        0 |
>> |      23 |       64 |        0 |        0 |
>> |      24 |       64 |        0 |        0 |
>> |      25 |       64 |        1 |        0 |
>> |      26 |       64 |        0 |        1 |
>> |      27 |       64 |        0 |        1 |
>> |      28 |       64 |        0 |        0 |
>> |      29 |       64 |        0 |        0 |
>> |      30 |       64 |        0 |        0 |
>> |      31 |       64 |        0 |        1 |
>> |      32 |       88 |        0 |        1 |
>> |      33 |       88 |        1 |        0 |
>> |      34 |       88 |        1 |        0 |
>> |      35 |       88 |        1 |        0 |
>> |      36 |       88 |        1 |        0 |
>> |      37 |       88 |        1 |        0 |
>> |      38 |       88 |        1 |        0 |
>> |      39 |       88 |        0 |        1 |
>> |      40 |       88 |        0 |        1 |
>> |      41 |       88 |        0 |        0 |
>> |      42 |       88 |        0 |        1 |
>> |      43 |       88 |        0 |        1 |
>> |      44 |       88 |        1 |        0 |
>> |      45 |       88 |        1 |        0 |
>> |      46 |       88 |        0 |        1 |
>> |      47 |       88 |        1 |        0 |
>> |      48 |      108 |        1 |        0 |
>> |      49 |      108 |        0 |        0 |
>> |      50 |      108 |        0 |        1 |
>> |      51 |      108 |        1 |        0 |
>> |      52 |      108 |        1 |        0 |
>> |      53 |      108 |        1 |        0 |
>> |      54 |      108 |        0 |        4 |
>> |      55 |      108 |        1 |        0 |
>> |      56 |      108 |        0 |        0 |
>> |      57 |      108 |        0 |        0 |
>> |      58 |      108 |        0 |        0 |
>> |      59 |      108 |        1 |        0 |
>> |      60 |      108 |        1 |        0 |
>> |      61 |      108 |        0 |        0 |
>> |      62 |      108 |        0 |        0 |
>> |      63 |      108 |        0 |        1 |
>> |      64 |      128 |        0 |        1 |
>> |      65 |      128 |        0 |        1 |
>> |      66 |      128 |        1 |        0 |
>> |      67 |      128 |        0 |        0 |
>> |      68 |      128 |        0 |        0 |
>> |      69 |      128 |        0 |        0 |
>> |      70 |      128 |        0 |        0 |
>> |      71 |      128 |        0 |        0 |
>> |      72 |      128 |        0 |        0 |
>> |      73 |      128 |        1 |        0 |
>> |      74 |      128 |        1 |        0 |
>> |      75 |      128 |        0 |        1 |
>> |      76 |      128 |        0 |        0 |
>> |      77 |      128 |        0 |        1 |
>> |      78 |      128 |        1 |        0 |
>> |      79 |      128 |        0 |        0 |
>> |      80 |      152 |        0 |        1 |
>> |      81 |      152 |        1 |        0 |
>> |      82 |      152 |        0 |        0 |
>> |      83 |      152 |        0 |        0 |
>> |      84 |      152 |        0 |        0 |
>> |      85 |      152 |        0 |        0 |
>> |      86 |      152 |        0 |        0 |
>> |      87 |      152 |        1 |        0 |
>> |      88 |      152 |        0 |        1 |
>> |      89 |      152 |        0 |        1 |
>> |      90 |      152 |        0 |        0 |
>> |      91 |      152 |        0 |        0 |
>> |      92 |      152 |        0 |        1 |
>> |      93 |      152 |        0 |        0 |
>> |      94 |      152 |        0 |        0 |
>> |      95 |      152 |        0 |        0 |
>> |      96 |      172 |        0 |        0 |
>> |      97 |      172 |        0 |        0 |
>> |      98 |      172 |        1 |        0 |
>> |      99 |      172 |        1 |        0 |
>>
>> --
>> View this message in context: http://shiro-user.582556.n2.nabble.com/Size-of-encrypted-text-tp7577530p7577550.html
>> Sent from the Shiro User mailing list archive at Nabble.com.

Re: Size of encrypted text?

Posted by Les Hazlewood <lh...@apache.org>.
Thanks for sharing this!  It is good to have some concrete numbers to
get a feeling for performance.

Thanks!

--
Les Hazlewood
CTO, Stormpath | @goStormpath
Stormpath Wins GigaOm's Structure LaunchPad Award! http://bit.ly/MvZkMk

On Wed, Jun 27, 2012 at 11:31 AM, drmike01 <ms...@gmail.com> wrote:
>
> This is the same data, except column two is the size of it from the
> toBase64() method, so a bit bigger but not really any slower.
>
>       0 |       44 |       10 |        0 |
> |       1 |       44 |        0 |        1 |
> |       2 |       44 |        0 |        0 |
> |       3 |       44 |        0 |        0 |
> |       4 |       44 |        0 |        0 |
> |       5 |       44 |        1 |        0 |
> |       6 |       44 |        1 |        0 |
> |       7 |       44 |        1 |        0 |
> |       8 |       44 |        0 |        0 |
> |       9 |       44 |        0 |        0 |
> |      10 |       44 |        1 |        0 |
> |      11 |       44 |        1 |        0 |
> |      12 |       44 |        0 |        1 |
> |      13 |       44 |        0 |        1 |
> |      14 |       44 |        0 |        0 |
> |      15 |       44 |        0 |        1 |
> |      16 |       64 |        0 |        1 |
> |      17 |       64 |        0 |        1 |
> |      18 |       64 |        0 |        1 |
> |      19 |       64 |        0 |        0 |
> |      20 |       64 |        0 |        0 |
> |      21 |       64 |        0 |        0 |
> |      22 |       64 |        0 |        0 |
> |      23 |       64 |        0 |        0 |
> |      24 |       64 |        0 |        0 |
> |      25 |       64 |        1 |        0 |
> |      26 |       64 |        0 |        1 |
> |      27 |       64 |        0 |        1 |
> |      28 |       64 |        0 |        0 |
> |      29 |       64 |        0 |        0 |
> |      30 |       64 |        0 |        0 |
> |      31 |       64 |        0 |        1 |
> |      32 |       88 |        0 |        1 |
> |      33 |       88 |        1 |        0 |
> |      34 |       88 |        1 |        0 |
> |      35 |       88 |        1 |        0 |
> |      36 |       88 |        1 |        0 |
> |      37 |       88 |        1 |        0 |
> |      38 |       88 |        1 |        0 |
> |      39 |       88 |        0 |        1 |
> |      40 |       88 |        0 |        1 |
> |      41 |       88 |        0 |        0 |
> |      42 |       88 |        0 |        1 |
> |      43 |       88 |        0 |        1 |
> |      44 |       88 |        1 |        0 |
> |      45 |       88 |        1 |        0 |
> |      46 |       88 |        0 |        1 |
> |      47 |       88 |        1 |        0 |
> |      48 |      108 |        1 |        0 |
> |      49 |      108 |        0 |        0 |
> |      50 |      108 |        0 |        1 |
> |      51 |      108 |        1 |        0 |
> |      52 |      108 |        1 |        0 |
> |      53 |      108 |        1 |        0 |
> |      54 |      108 |        0 |        4 |
> |      55 |      108 |        1 |        0 |
> |      56 |      108 |        0 |        0 |
> |      57 |      108 |        0 |        0 |
> |      58 |      108 |        0 |        0 |
> |      59 |      108 |        1 |        0 |
> |      60 |      108 |        1 |        0 |
> |      61 |      108 |        0 |        0 |
> |      62 |      108 |        0 |        0 |
> |      63 |      108 |        0 |        1 |
> |      64 |      128 |        0 |        1 |
> |      65 |      128 |        0 |        1 |
> |      66 |      128 |        1 |        0 |
> |      67 |      128 |        0 |        0 |
> |      68 |      128 |        0 |        0 |
> |      69 |      128 |        0 |        0 |
> |      70 |      128 |        0 |        0 |
> |      71 |      128 |        0 |        0 |
> |      72 |      128 |        0 |        0 |
> |      73 |      128 |        1 |        0 |
> |      74 |      128 |        1 |        0 |
> |      75 |      128 |        0 |        1 |
> |      76 |      128 |        0 |        0 |
> |      77 |      128 |        0 |        1 |
> |      78 |      128 |        1 |        0 |
> |      79 |      128 |        0 |        0 |
> |      80 |      152 |        0 |        1 |
> |      81 |      152 |        1 |        0 |
> |      82 |      152 |        0 |        0 |
> |      83 |      152 |        0 |        0 |
> |      84 |      152 |        0 |        0 |
> |      85 |      152 |        0 |        0 |
> |      86 |      152 |        0 |        0 |
> |      87 |      152 |        1 |        0 |
> |      88 |      152 |        0 |        1 |
> |      89 |      152 |        0 |        1 |
> |      90 |      152 |        0 |        0 |
> |      91 |      152 |        0 |        0 |
> |      92 |      152 |        0 |        1 |
> |      93 |      152 |        0 |        0 |
> |      94 |      152 |        0 |        0 |
> |      95 |      152 |        0 |        0 |
> |      96 |      172 |        0 |        0 |
> |      97 |      172 |        0 |        0 |
> |      98 |      172 |        1 |        0 |
> |      99 |      172 |        1 |        0 |
>
> --
> View this message in context: http://shiro-user.582556.n2.nabble.com/Size-of-encrypted-text-tp7577530p7577550.html
> Sent from the Shiro User mailing list archive at Nabble.com.

Re: Size of encrypted text?

Posted by drmike01 <ms...@gmail.com>.
This is the same data, except column two is the size of it from the
toBase64() method, so a bit bigger but not really any slower.

       0 |       44 |       10 |        0 | 
|       1 |       44 |        0 |        1 | 
|       2 |       44 |        0 |        0 | 
|       3 |       44 |        0 |        0 | 
|       4 |       44 |        0 |        0 | 
|       5 |       44 |        1 |        0 | 
|       6 |       44 |        1 |        0 | 
|       7 |       44 |        1 |        0 | 
|       8 |       44 |        0 |        0 | 
|       9 |       44 |        0 |        0 | 
|      10 |       44 |        1 |        0 | 
|      11 |       44 |        1 |        0 | 
|      12 |       44 |        0 |        1 | 
|      13 |       44 |        0 |        1 | 
|      14 |       44 |        0 |        0 | 
|      15 |       44 |        0 |        1 | 
|      16 |       64 |        0 |        1 | 
|      17 |       64 |        0 |        1 | 
|      18 |       64 |        0 |        1 | 
|      19 |       64 |        0 |        0 | 
|      20 |       64 |        0 |        0 | 
|      21 |       64 |        0 |        0 | 
|      22 |       64 |        0 |        0 | 
|      23 |       64 |        0 |        0 | 
|      24 |       64 |        0 |        0 | 
|      25 |       64 |        1 |        0 | 
|      26 |       64 |        0 |        1 | 
|      27 |       64 |        0 |        1 | 
|      28 |       64 |        0 |        0 | 
|      29 |       64 |        0 |        0 | 
|      30 |       64 |        0 |        0 | 
|      31 |       64 |        0 |        1 | 
|      32 |       88 |        0 |        1 | 
|      33 |       88 |        1 |        0 | 
|      34 |       88 |        1 |        0 | 
|      35 |       88 |        1 |        0 | 
|      36 |       88 |        1 |        0 | 
|      37 |       88 |        1 |        0 | 
|      38 |       88 |        1 |        0 | 
|      39 |       88 |        0 |        1 | 
|      40 |       88 |        0 |        1 | 
|      41 |       88 |        0 |        0 | 
|      42 |       88 |        0 |        1 | 
|      43 |       88 |        0 |        1 | 
|      44 |       88 |        1 |        0 | 
|      45 |       88 |        1 |        0 | 
|      46 |       88 |        0 |        1 | 
|      47 |       88 |        1 |        0 | 
|      48 |      108 |        1 |        0 | 
|      49 |      108 |        0 |        0 | 
|      50 |      108 |        0 |        1 | 
|      51 |      108 |        1 |        0 | 
|      52 |      108 |        1 |        0 | 
|      53 |      108 |        1 |        0 | 
|      54 |      108 |        0 |        4 | 
|      55 |      108 |        1 |        0 | 
|      56 |      108 |        0 |        0 | 
|      57 |      108 |        0 |        0 | 
|      58 |      108 |        0 |        0 | 
|      59 |      108 |        1 |        0 | 
|      60 |      108 |        1 |        0 | 
|      61 |      108 |        0 |        0 | 
|      62 |      108 |        0 |        0 | 
|      63 |      108 |        0 |        1 | 
|      64 |      128 |        0 |        1 | 
|      65 |      128 |        0 |        1 | 
|      66 |      128 |        1 |        0 | 
|      67 |      128 |        0 |        0 | 
|      68 |      128 |        0 |        0 | 
|      69 |      128 |        0 |        0 | 
|      70 |      128 |        0 |        0 | 
|      71 |      128 |        0 |        0 | 
|      72 |      128 |        0 |        0 | 
|      73 |      128 |        1 |        0 | 
|      74 |      128 |        1 |        0 | 
|      75 |      128 |        0 |        1 | 
|      76 |      128 |        0 |        0 | 
|      77 |      128 |        0 |        1 | 
|      78 |      128 |        1 |        0 | 
|      79 |      128 |        0 |        0 | 
|      80 |      152 |        0 |        1 | 
|      81 |      152 |        1 |        0 | 
|      82 |      152 |        0 |        0 | 
|      83 |      152 |        0 |        0 | 
|      84 |      152 |        0 |        0 | 
|      85 |      152 |        0 |        0 | 
|      86 |      152 |        0 |        0 | 
|      87 |      152 |        1 |        0 | 
|      88 |      152 |        0 |        1 | 
|      89 |      152 |        0 |        1 | 
|      90 |      152 |        0 |        0 | 
|      91 |      152 |        0 |        0 | 
|      92 |      152 |        0 |        1 | 
|      93 |      152 |        0 |        0 | 
|      94 |      152 |        0 |        0 | 
|      95 |      152 |        0 |        0 | 
|      96 |      172 |        0 |        0 | 
|      97 |      172 |        0 |        0 | 
|      98 |      172 |        1 |        0 | 
|      99 |      172 |        1 |        0 | 

--
View this message in context: http://shiro-user.582556.n2.nabble.com/Size-of-encrypted-text-tp7577530p7577550.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Size of encrypted text?

Posted by drmike01 <ms...@gmail.com>.
Thanks Les, that's very helpful, I wouldn't have known about the additional
IV piece.

I ran some performance tests, thought I would share here in case anybody
else is curious. This is using an AES-256 bit key (instead of the default
128). You'll note the encoding/decoding is incredibly fast (this is running
locally on my late-2011 MBP), which was great news for my app.

Columns:
1) string size
2) encoded string size
3) time to encode in msec
4) time to decode in msec


|       0 |       32 |       18 |        1 | 
|       0 |       32 |        1 |        0 | 
|       1 |       32 |        1 |        0 | 
|       1 |       32 |        0 |        0 | 
|       2 |       32 |        0 |        1 | 
|       2 |       32 |        0 |        1 | 
|       3 |       32 |        0 |        1 | 
|       3 |       32 |        0 |        1 | 
|       4 |       32 |        0 |        0 | 
|       4 |       32 |        0 |        1 | 
|       5 |       32 |        0 |        1 | 
|       5 |       32 |        1 |        0 | 
|       6 |       32 |        1 |        0 | 
|       6 |       32 |        1 |        0 | 
|       7 |       32 |        1 |        0 | 
|       7 |       32 |        0 |        1 | 
|       8 |       32 |        1 |        0 | 
|       8 |       32 |        1 |        0 | 
|       9 |       32 |        1 |        0 | 
|       9 |       32 |        1 |        0 | 
|      10 |       32 |        1 |        0 | 
|      10 |       32 |        1 |        0 | 
|      11 |       32 |        0 |        0 | 
|      11 |       32 |        0 |        0 | 
|      12 |       32 |        0 |        1 | 
|      12 |       32 |        0 |        1 | 
|      13 |       32 |        1 |        0 | 
|      13 |       32 |        1 |        0 | 
|      14 |       32 |        1 |        0 | 
|      14 |       32 |        1 |        0 | 
|      15 |       32 |        0 |        1 | 
|      15 |       32 |        1 |        0 | 
|      16 |       48 |        0 |        0 | 
|      16 |       48 |        0 |        0 | 
|      17 |       48 |        0 |        1 | 
|      17 |       48 |        0 |        1 | 
|      18 |       48 |        0 |        1 | 
|      18 |       48 |        1 |        0 | 
|      19 |       48 |        0 |        1 | 
|      19 |       48 |        1 |        0 | 
|      20 |       48 |        0 |        1 | 
|      20 |       48 |        1 |        0 | 
|      21 |       48 |        0 |        1 | 
|      21 |       48 |        0 |        1 | 
|      22 |       48 |        1 |        0 | 
|      22 |       48 |        4 |        1 | 
|      23 |       48 |        1 |        0 | 
|      23 |       48 |        1 |        0 | 
|      24 |       48 |        0 |        0 | 
|      24 |       48 |        0 |        1 | 
|      25 |       48 |        1 |        0 | 
|      25 |       48 |        0 |        0 | 
|      26 |       48 |        0 |        0 | 
|      26 |       48 |        0 |        0 | 
|      27 |       48 |        0 |        1 | 
|      27 |       48 |        0 |        1 | 
|      28 |       48 |        0 |        1 | 
|      28 |       48 |        0 |        1 | 
|      29 |       48 |        1 |        0 | 
|      29 |       48 |        0 |        1 | 
|      30 |       48 |        1 |        0 | 
|      30 |       48 |        0 |        1 | 
|      31 |       48 |        1 |        0 | 
|      31 |       48 |        1 |        0 | 
|      32 |       64 |        0 |        1 | 
|      32 |       64 |        1 |        0 | 
|      33 |       64 |        0 |        1 | 
|      33 |       64 |        0 |        0 | 
|      34 |       64 |        0 |        1 | 
|      34 |       64 |        0 |        1 | 
|      35 |       64 |        0 |        1 | 
|      35 |       64 |        0 |        1 | 
|      36 |       64 |        0 |        1 | 
|      36 |       64 |        0 |        0 | 
|      37 |       64 |        0 |        0 | 
|      37 |       64 |        0 |        0 | 
|      38 |       64 |        0 |        0 | 
|      38 |       64 |        0 |        0 | 
|      39 |       64 |        1 |        0 | 
|      39 |       64 |        1 |        0 | 
|      40 |       64 |        1 |        0 | 
|      40 |       64 |        1 |        0 | 
|      41 |       64 |        0 |        1 | 
|      41 |       64 |        0 |        1 | 
|      42 |       64 |        0 |        1 | 
|      42 |       64 |        0 |        1 | 
|      43 |       64 |        0 |        1 | 
|      43 |       64 |        0 |        1 | 
|      44 |       64 |        0 |        1 | 
|      44 |       64 |        0 |        0 | 
|      45 |       64 |        0 |        0 | 
|      45 |       64 |        0 |        1 | 
|      46 |       64 |        0 |        1 | 
|      46 |       64 |        0 |        1 | 
|      47 |       64 |        0 |        1 | 
|      47 |       64 |        0 |        1 | 
|      48 |       80 |        1 |        0 | 
|      48 |       80 |        1 |        0 | 
|      49 |       80 |        1 |        0 | 
|      49 |       80 |        1 |        0 | 
|      50 |       80 |        1 |        0 | 
|      50 |       80 |        1 |        0 | 
|      51 |       80 |        1 |        0 | 
|      51 |       80 |        0 |        1 | 
|      52 |       80 |        0 |        1 | 
|      52 |       80 |        1 |        0 | 
|      53 |       80 |        1 |        0 | 
|      53 |       80 |        1 |        0 | 
|      54 |       80 |        1 |        0 | 
|      54 |       80 |        1 |        0 | 
|      55 |       80 |        1 |        0 | 
|      55 |       80 |        1 |        0 | 
|      56 |       80 |        0 |        0 | 
|      56 |       80 |        0 |        0 | 
|      57 |       80 |        0 |        0 | 
|      57 |       80 |        0 |        1 | 
|      58 |       80 |        0 |        1 | 
|      58 |       80 |        1 |        0 | 
|      59 |       80 |        0 |        1 | 
|      59 |       80 |        0 |        1 | 
|      60 |       80 |        1 |        0 | 
|      60 |       80 |        1 |        0 | 
|      61 |       80 |        0 |        0 | 
|      61 |       80 |        1 |        0 | 
|      62 |       80 |        0 |        0 | 
|      62 |       80 |        0 |        0 | 
|      63 |       80 |        0 |        0 | 
|      63 |       80 |        0 |        0 | 
|      64 |       96 |        0 |        0 | 
|      64 |       96 |        0 |        0 | 
|      65 |       96 |        0 |        0 | 
|      65 |       96 |        0 |        0 | 
|      66 |       96 |        0 |        1 | 
|      66 |       96 |        0 |        1 | 
|      67 |       96 |        0 |        1 | 
|      67 |       96 |        0 |        1 | 
|      68 |       96 |        0 |        1 | 
|      68 |       96 |        0 |        0 | 
|      69 |       96 |        0 |        0 | 
|      69 |       96 |        0 |        0 | 
|      70 |       96 |        0 |        0 | 
|      70 |       96 |        1 |        0 | 
|      71 |       96 |        1 |        0 | 
|      71 |       96 |        0 |        1 | 
|      72 |       96 |        0 |        1 | 
|      72 |       96 |        0 |        1 | 
|      73 |       96 |        0 |        0 | 
|      73 |       96 |        0 |        0 | 
|      74 |       96 |        0 |        0 | 
|      74 |       96 |        1 |        0 | 
|      75 |       96 |        1 |        0 | 
|      75 |       96 |        1 |        0 | 
|      76 |       96 |        1 |        0 | 
|      76 |       96 |        0 |        1 | 
|      77 |       96 |        1 |        0 | 
|      77 |       96 |        1 |        0 | 
|      78 |       96 |        1 |        0 | 
|      78 |       96 |        1 |        0 | 
|      79 |       96 |        1 |        0 | 
|      79 |       96 |        1 |        0 | 
|      80 |      112 |        0 |        1 | 
|      80 |      112 |        1 |        0 | 
|      81 |      112 |        1 |        0 | 
|      81 |      112 |        1 |        0 | 
|      82 |      112 |        1 |        0 | 
|      82 |      112 |        1 |        0 | 
|      83 |      112 |        0 |        0 | 
|      83 |      112 |        1 |        0 | 
|      84 |      112 |        1 |        0 | 
|      84 |      112 |        1 |        0 | 
|      85 |      112 |        1 |        0 | 
|      85 |      112 |        1 |        0 | 
|      86 |      112 |        1 |        0 | 
|      86 |      112 |        0 |        1 | 
|      87 |      112 |        0 |        1 | 
|      87 |      112 |        0 |        0 | 
|      88 |      112 |        0 |        0 | 
|      88 |      112 |        0 |        0 | 
|      89 |      112 |        0 |        1 | 
|      89 |      112 |        0 |        1 | 
|      90 |      112 |        0 |        1 | 
|      90 |      112 |        0 |        1 | 
|      91 |      112 |        1 |        0 | 
|      91 |      112 |        1 |        0 | 
|      92 |      112 |        1 |        0 | 
|      92 |      112 |        1 |        0 | 
|      93 |      112 |        1 |        0 | 
|      93 |      112 |        0 |        1 | 
|      94 |      112 |        0 |        0 | 
|      94 |      112 |        0 |        0 | 
|      95 |      112 |        0 |        1 | 
|      95 |      112 |        0 |        1 | 
|      96 |      128 |        1 |        0 | 
|      96 |      128 |        1 |        0 | 
|      97 |      128 |        0 |        0 | 
|      97 |      128 |        0 |        0 | 
|      98 |      128 |        0 |        1 | 
|      98 |      128 |        0 |        1 | 
|      99 |      128 |        1 |        0 | 
|      99 |      128 |        1 |        0 | 


--
View this message in context: http://shiro-user.582556.n2.nabble.com/Size-of-encrypted-text-tp7577530p7577549.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Size of encrypted text?

Posted by Les Hazlewood <lh...@apache.org>.
Hiya,

Yes, the AES algorithm has a block size of 128 bits (16 bytes), so the
encrypted output will be a multiple of that.  Any final block less than the
block size will be 'filled out', i.e. padded, according to the crypto
PaddingScheme, which is PKCS5 by default.

Note however, that Shiro's encryption defaults (for CipherServices anyway)
automatically generate an Initialization Vector and prepend it to the
output (this is pretty much necessary for proper security: no IVs =
easier-to-break crypto).  The default Initialization Vector size is also
128 bits for AES, so your encrypted output size will be (IV bytes.length +
encrypted bytes.length).  This result mod 16 should equal zero.

The resulting byte array can be stored however you wish. BINARY or BLOBs
are valid.  Another way is to call ByteSource.toBase64() on the encrypted
output and store the resulting string in a VARCHAR or CLOB column.  Of
course the latter approach requires more computation, but depending on your
data store, could be a desirable approach.

Also note that because IVs are prepended by default, it is assumed that
whatever is performing the decryption knows how to 'slice off' the IV to
reference it appropriately.  Shiro does this of course, but if you have
something else that needs to decrypt Shiro's encryption output, keep that
in mind.

HTH!

--
Les Hazlewood
CTO, Stormpath | http://stormpath.com <http://www.stormpath.com/> |
888.391.5282
twitter: @lhazlewood | http://twitter.com/lhazlewood
blog: http://leshazlewood.com
stormpath blog:
http://www.stormpath.com/blog<http://www.stormpath.com/blog/index>

On Wed, Jun 20, 2012 at 1:35 PM, drmike01 <ms...@gmail.com> wrote:

> Quick question (hopefully). I'm planning on using the crypto modules to
> encrypt some fields in my database (MySQL) using AES-256.  My understanding
> of doing this for standard Java crypto is that it encrypts in 16-byte
> blocks, and so the total length of it should be, at most, the next multiple
> of 16 longer than the actual data (I think it may actually be slightly
> shorter than that, but that doesn't really matter to me). It also should be
> stored as some BINARY or BLOB type.
>
> My question is whether or not the same rules apply for Shiro.  The JavaDoc
> doesn't mention it, although it makes sense that it would because it's
> making the same sort of changes to the underlying data.
>
> Thanks in advance!
>
> --
> View this message in context:
> http://shiro-user.582556.n2.nabble.com/Size-of-encrypted-text-tp7577530.html
> Sent from the Shiro User mailing list archive at Nabble.com.
>