works with stock openssl keys. refactored.