Eventhough the methods are called setPublicKey and setPrivateKey, remember that they are only alias to setKey, so you can pass them both a private or a public openssl key, just remember that setting a public key allows you to only encrypt.