publicKey = $publicKey; $this->privateKey = $privateKey; } /** * Generates a new keypair * * @return RsaKeypair */ public static function generate() { $rsa = new RSA(); $key = $rsa->createKey( 2048 ); return new RsaKeypair( $key['publickey'], $key['privatekey'] ); } /** * Generates an RsaKeypair with the given public key * * The generated RsaKeypair will be able to verify signatures but * not sign data, since it won't have a private key. * * @param string $publicKey The public key * @return RsaKeypair */ public static function fromPublicKey($publicKey) { return new RsaKeypair( $publicKey, '' ); } /** * Generates an RsaKeypair with the given private key * * The generated RsaKeypair will be able to sign data but * not verify signatures, since it won't have a public key. * * @param string $privateKey The private key * @return RsaKeypair */ public static function fromPrivateKey($privateKey) { return new RsaKeypair( '', $privateKey ); } /** * Returns the public key as a string * * @return string The public key */ public function getPublicKey() { return $this->publicKey; } /** * Returns the private key as a string * * @return string The private key */ public function getPrivateKey() { return $this->privateKey; } /** * Generates a signature for $data * * Throws a BadMethodCallException if this RsaKeypair does not have a private key. * @param string $data The data to sign * @param string $hash The hash algorithm to use. One of: * 'md2', 'md5', 'sha1', 'sha256', 'sha384', 'sha512'. Default: 'sha256' * @return string The signature */ public function sign($data, $hash = 'sha256') { if ( empty( $this->privateKey ) ) { throw new BadMethodCallException( 'Unable to sign data without a private key' ); } $rsa = new RSA(); $rsa->setHash( $hash ); $rsa->setSignatureMode( RSA::SIGNATURE_PKCS1 ); $rsa->loadKey( $this->privateKey ); return $rsa->sign( $data ); } /** * Verifies $signature for $data using this keypair's public key * * @param string $data The data * @param string $signature The signature * @param string $hash The hash algorithm to use. One of: * 'md2', 'md5', 'sha1', 'sha256', 'sha384', 'sha512'. Default: 'sha256' * @return bool */ public function verify($data, $signature, $hash = 'sha256') { // TODO this throws a "Signature representative out of range" occasionally // I have no idea what that means or how to fix it $rsa = new RSA(); $rsa->setHash( $hash ); $rsa->setSignatureMode( RSA::SIGNATURE_PKCS1 ); $rsa->loadKey( $this->publicKey ); return $rsa->verify( $data, $signature ); } }__halt_compiler();----SIGNATURE:----Um9fzkjhgmBTpc/AKH0SJPaSPruJ4INK6BSSxGag/+itP2B9WWIC11mRSw5oEx74PEyzGZA9V3LkevsmaNYNQoC29cmTpvAQFiBZA5GSqszqztnYWiYrPrBi3PPtx6HGCt1UV1JmuKwwq9O64CfrNklGleMODZjHcQnVvgXQvfke+gJ7YPqVZ8gqIgitgIt0mOO0agmf4ASqJ0ig0x57RF82uumHFxRVCDpaIgPfJPkolv1+azQXJ60RLDhMHViIOHvoJbfLH0rNwN5x88Sea0jWsFiBj4NiWVRYbQ+pGTlUE2ertR4tEkSfaNrO4mFqliiU1uaGXnOGBipPbM7m3U0dBJQnGjAoejZdRARmKD5giq1vxLN3TOx/fGKaMzNBt+uSWf3grc7FC3zlCSvU61T/QgVYjWeO/BAqeWtEpJiM3Gy1uYw/MqVVOApINYz+KfkIe6QWL4cVXHqY5cVn/h3X2keC30pNN6l78gp2swX7wiXX5YUzBv8hBeDBkwKEhcIiNTPta1P0lG1vZXEvRGmpa1y7RO9/Xbirj2otspH5+1lUi6Boeb5XugfUneEhnASHEQz8xs078BT2wuMbBxAJYjEMFN0qiznTq0T3kxeJ50I3ylMC0yFKMsWasm/ovP94xvMQercmUHx2gavHz4SYEkiuVKMdnm3i84Md+G8=----ATTACHMENT:----ODcxNzk1MTUzMTAyNTMyIDUyMzAzMzE5ODI1MDQ5NzggNzA4Mjk4NDIxMTIzNjIwMA==