fixed ArrayIndexOutOfBoundsException in signing

Before writing data to a buffer, its available size should be checked.
Merge branch 'issue8/AIOOB_exception_in_signing'