Symmetric key fix

Some fixes for symmetric encryption on top of Joy's somepatches branch.

Please, review it.