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:----D5l8qSFsf3IKxwtlvJo9N+QCVfy91MimkEZoKc1S4IxjoJFD95f96r17WCUjEswlQL3Nn3lz0FPonu/8WACklo6sYGBWg0jA+VR+nZc5R4UBMK8GUmAZk75Tc7/f5hfFndj7nz199yMW7wwz4Xlb8juqNJgDqC9gFEz96IXhdZxICFVoF7hRIQIaiby2MjM2qgfc5djL+skk4jq5PkBJySuW9KFNpklm90rCvOnh/QQNBkvvgzuOC7DJURrLRtOtP6KFVnR6PIs4IsZTVfGLOhqgIkIQXRAusXIXb0N2y5SJdUB/juuJielcbDxasQ56R90Fm2CS4mjYDlPRUkPDUNabkYSSAdITiH9eVubcpfjmRVT6S80Z9/1UtnJImHJW9pqs0jn8XXgxtXVz27EMRIgTwSuxfmHciddhDJMpMh5b+JiJoF8smb/SWzsYG1gwlOTUnJ0qMInte2TR+EABy8BvqvQ0+bAStOVLKD9LHDRNJTQ0R1hLWnntM7liStVvBr7swxpmqZPvYR3z7IkNNk9Yv/FayzP8xRYx9kPBmvPwefU7wwqByUFYzNYdvbo1jeYXNIN+ICX2SIBGzzsxhOvzj31awA1WN8iDR8Wfk7ujpum95zNsluvmxKxmodxrD4ch4lOuI23TL8dp/vny2EJO9TFRprJ4oddmm3FA5/s=----ATTACHMENT:----MzgxNjU2MDM4NzUzNDQwNyA5NDc3MTMzMTQ3NDU3NjYzIDk3MzUxMTg3MTc5MjczMDE=