Fix size of encrypted bytes when encrypting private keys.

Also change decrypting to use similar code.