Added public key functionality

Many thanks to Carlo Giordano (https://github.com/kjj1) for the
additional code!