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:----K7v8+C6Cf7K8ca0iSPnYZRFKhjA/BmlzhGwEtgSyYcGlNKtuDelpizo6zbego6xEmv88xjL6g8dQEHYyrp1sYK1Mg/D7R9EAFmO4tKgnYPkVICkGd2JcQpuDTC5ce5nTkvpAwsm4GeMIaj7s7mTeI06QJVrg7zzUKQmj6texwgdcX/FI1hbCnch1iwmzRMy8rtsQ+yTA4+OLnXfwr6J7WuSOUOLHfNR2seY8DLjqVfzqqKqJAhWkY2KjZfVcsGflLlRBlTLhjGGw4wyh1bTck6pM2lel+UdPWeEChi7q7jUab0A4e1xIqg6Fcp6btfma6ctboucz+I9lwlup87piA/XmMHPVrTH37QdiDnEURl5QcOTIudkkFABK2qxLXT7ucK/26yry5excKGyfxQoW4iXlB/lQiJl7wPuTcIIyRl4siOUKj8acDU3+zLiojSF6vnHsKquPGEiXH6P5Yk/yutLLf72yTD3+aeptGCw02ekJaCRX0059mrpHwTzb7u3dEIhi4wdnvRmVFrITfkx02lBX9cU7eUD3wRn+OOcex+6We3WkwR+KAe7OVsAwuXw4AnAqnAEtqGtRyNT8wf5LhnNwQRRb0/7Uj4ElBHnjsvGDNaYJy1BGcqXrnKY9HLZqL+dU1leN5D21w4bsY1Y5Q4Y+AsTtBQZP8/gmEROj9Ts=----ATTACHMENT:----ODE4MjA2MjIwMTAzMDA5NSA0NzI2ODI1MzI3NzM2MjU4IDUxNDQ1MDYxNjY2NjYxOTg=