Complete change of encode() API and implementation
Merge pull request #9 from skarkkai-p/sign-rewrite

A rewrite of encode()/sign()