Bugfixes to public/private key data retrieval code.  Added more coverage to relevant test cases.