PKCS generator, taken from Robs wonderful work on GPG