context = label || 0x00 ||
length(recipient_public) || recipient_public ||
length(sender_public) || sender_public.

@param string $userPublicKey

@return string
437323
private function createContext($userPublicKey)
    {
        $label = 'P-256';
        // The two length fields are encoded as a two octet unsigned integer in network byte order.
        $recipientPublicLength = chr(0).chr(strlen($userPublicKey));
        $senderPublicLength = chr(0).chr(strlen($this->publicKeyContent));

        return $label.chr(0).$recipientPublicLength.$userPublicKey.$senderPublicLength.$this->publicKeyContent;
    }
628421
def user_label(user: User) -> Optional[str]:
    """"""
    if user:
        if user.first_name and user.last_name:
            return user.first_name + ' ' + user.last_name
        else:
            return user.username

    return None
157102
public function getLabelOfNameAndUserId(string $labelName, string $userId)
    {
        foreach ($this->labels as $label) {
            /** @var GmailLabelInterface $label */
            if ($label->getName() === $labelName && $label->getUserId() === $userId) {
                return $label;
            }
        }

        return;
    }
859877
public static function get_contexts_for_userid(int $userid) : contextlist {
        global $DB;

        $contextlist = new contextlist();

        $publishstates = [
            NOTES_STATE_PUBLIC,
            NOTES_STATE_SITE
        ];
        list($publishstatesql, $publishstateparams) = $DB->get_in_or_equal($publishstates, SQL_PARAMS_NAMED);

        // Retrieve all the Course contexts associated with notes written by the user, and also written about the user.
        // Only notes written about the user that are public or site wide will be exported.
        $sql = "SELECT c.id
                  FROM {context} c
            INNER JOIN {post} p ON p.courseid = c.instanceid AND c.contextlevel = :contextcoursewrittenby
                 WHERE p.module = 'notes'
                   AND p.usermodified = :usermodified
                 UNION
                SELECT c.id
                  FROM {context} c
            INNER JOIN {post} p ON p.courseid = c.instanceid AND c.contextlevel = :contextcoursewrittenfor
                 WHERE p.module = 'notes'
                   AND p.userid = :userid
                   AND p.publishstate {$publishstatesql}";

        $params = [
            'contextcoursewrittenby'  => CONTEXT_COURSE,
            'usermodified'            => $userid,
            'contextcoursewrittenfor' => CONTEXT_COURSE,
            'userid'                  => $userid
        ];
        $params += $publishstateparams;

        $contextlist->add_from_sql($sql, $params);

        return $contextlist;
    }
284831
protected function pkey(string $key, $userId): string
    {
        return sprintf('%s(%s).%s', self::PREFERENCES_KEY_PREFIX, $userId, $key);
    }
498107
public function getTokenForPublicKey($publicKey)
    {
        if (!$this->accessControlManager->hasAccessEntityForName(self::ACCESS_ENTITY_TYPE, $publicKey)) {
            return false;
        }
        
        // Get the access entity
        $accessEntity = $this->accessControlManager->getAccessEntityForName(self::ACCESS_ENTITY_TYPE, $publicKey);

        if ($accessEntity === false) {
            return false;
        }
        
        return $accessEntity;
    }
372595
public function parseEntity(User $entity) {

        $output = [
            $this->encodeInteger($entity->getUserNumber(), 9),
            $this->encodeInteger($entity->getCustomerNumber(), 9),
            $this->encodeString($entity->getTitle(), 10),
            $this->encodeString($entity->getSurname(), 25),
            $this->encodeString($entity->getFirstname(), 25),
            $this->encodeDate($entity->getDateBirth()),
            $this->encodeString($entity->getParkingSpace(), 5),
            $this->encodeString($entity->getRemarks(), 50),
            $this->encodeDateTime($entity->getDatetimeLastModification()),
            $this->encodeBoolean($entity->getDeletedRecord()),
            $this->encodeString($entity->getIdentificationNumber(), 20),
            $this->encodeBoolean($entity->getCheckLicensePlate()),
            $this->encodeBoolean($entity->getPassageLicensePlatePermitted()),
            $this->encodeBoolean($entity->getExcessTimesCreditCard()),
            $this->encodeString($entity->getCreditCardNumber(), 20),
            $this->encodeDate($entity->getExpiryDate()),
            $this->encodeString($entity->getRemarks2(), 50),
            $this->encodeString($entity->getRemarks3(), 50),
            $this->encodeString($entity->getDivision(), 50),
            $this->encodeString($entity->getEmail(), 120),
            $this->encodeBoolean($entity->getGroupCounting()),
            $this->encodeInteger($entity->getETicketTypeP(), 1),
            $this->encodeString($entity->getETicketEmailTelephone(), 120),
            $this->encodeInteger($entity->getETicketAuthentication(), 1),
            $this->encodeInteger($entity->getETicketServiceTyp(), 1),
            $this->encodeInteger($entity->getETicketServiceArt(), 1),
        ];

        return implode(";", $output);
    }
1326543
public function show($username, $repository, $label)
    {
        return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label));
    }
815528
public function encryptByPublicKey_data($data, $publickey = '')
	{
		$RSACrypt = new RSACrypt();

		if ($publickey != "") {
			$RSACrypt->pubkey = $publickey;
		}
		$crypt_res = "";
		for ($i = 0; $i < ((strlen($data) - strlen($data) % 117) / 117 + 1); $i++) {
			$crypt_res = $crypt_res . ($RSACrypt->encryptByPublicKey(mb_strcut($data, $i * 117, 117, 'utf-8')));
		}
		return $crypt_res;
	}
991964
public static function decryptRsaPublic(string $data, string $publicKey, string $format = null): string
    {
        $data = self::toRaw($data, $format);
        $key = \openssl_pkey_get_public($publicKey);

        $decrypted = '';
        if (!\openssl_public_decrypt($data, $decrypted, $key, OPENSSL_PKCS1_OAEP_PADDING)) {
            throw new CryptoException('RSA public decrypt error: ' . openssl_error_string());
        }
        \openssl_pkey_free($key);

        return $decrypted;
    }
705052
public String getPublicKey() {
        RSAPublicKey key = InstanceIdentityProvider.RSA.getPublicKey();
        if (key == null) {
            return null;
        }
        byte[] encoded = Base64.encodeBase64(key.getEncoded());
        int index = 0;
        StringBuilder buf = new StringBuilder(encoded.length + 20);
        while (index < encoded.length) {
            int len = Math.min(64, encoded.length - index);
            if (index > 0) {
                buf.append("\n");
            }
            buf.append(new String(encoded, index, len, Charsets.UTF_8));
            index += len;
        }
        return String.format("-----BEGIN PUBLIC KEY-----%n%s%n-----END PUBLIC KEY-----%n", buf.toString());
    }
729871
public function getEccKey() : PublicKeyInterface
    {
        $math = EccFactory::getAdapter();
        $generator = EccFactory::getNistCurves()->generator256();
        $pointSerializer = new UncompressedPointSerializer($math);
        $point = $pointSerializer->unserialize($generator->getCurve(), bin2hex($this->getRawKeyMaterial()));

        return $generator->getPublicKeyFrom($point->getX(), $point->getY(), $generator->getOrder());
    }
1314138
public function getServerPublicKey($raw = false)
    {
        if ($raw) {
            return $this->publicKeyContent;
        }

        return Base64Url::encode($this->publicKeyContent);
    }
924282
protected byte[] getPublicKey(KeyPair keyPair) {
        DHPublicKey incomingPublicKey = (DHPublicKey) keyPair.getPublic();
        BigInteger dhY = incomingPublicKey.getY();
        if (log.isDebugEnabled()) {
            log.debug("Public key: {}", Hex.encodeHexString(BigIntegers.asUnsignedByteArray(dhY)));
        }
        return Arrays.copyOfRange(BigIntegers.asUnsignedByteArray(dhY), 0, KEY_LENGTH);
    }
849103
public function updateForUserClass(string $yamlSource, UserClassConfiguration $userConfig, string $userClass): string
    {
        $this->manipulator = new YamlSourceManipulator($yamlSource);

        $this->normalizeSecurityYamlFile();

        $this->updateProviders($userConfig, $userClass);

        if ($userConfig->hasPassword()) {
            $this->updateEncoders($userConfig, $userClass);
        }

        $contents = $this->manipulator->getContents();
        $this->manipulator = null;

        return $contents;
    }
178763
function _formatSubjectPublicKey()
    {
        if (!isset($this->publicKey) || !is_object($this->publicKey)) {
            return false;
        }

        switch (strtolower(get_class($this->publicKey))) {
            case 'crypt_rsa':
                // the following two return statements do the same thing. i dunno.. i just prefer the later for some reason.
                // the former is a good example of how to do fuzzing on the public key
                //return new File_ASN1_Element(base64_decode(preg_replace('#-.+-|[\r\n]#', '', $this->publicKey->getPublicKey())));
                return array(
                    'algorithm' => array('algorithm' => 'rsaEncryption'),
                    'subjectPublicKey' => $this->publicKey->getPublicKey(CRYPT_RSA_PUBLIC_FORMAT_PKCS1)
                );
            default:
                return false;
        }
    }
1222767
protected function render_user_picture(user_picture $userpicture) {
        global $CFG, $DB;

        $user = $userpicture->user;
        $canviewfullnames = has_capability('moodle/site:viewfullnames', $this->page->context);

        if ($userpicture->alttext) {
            if (!empty($user->imagealt)) {
                $alt = $user->imagealt;
            } else {
                $alt = get_string('pictureof', '', fullname($user, $canviewfullnames));
            }
        } else {
            $alt = '';
        }

        if (empty($userpicture->size)) {
            $size = 35;
        } else if ($userpicture->size === true or $userpicture->size == 1) {
            $size = 100;
        } else {
            $size = $userpicture->size;
        }

        $class = $userpicture->class;

        if ($user->picture == 0) {
            $class .= ' defaultuserpic';
        }

        $src = $userpicture->get_url($this->page, $this);

        $attributes = array('src' => $src, 'class' => $class, 'width' => $size, 'height' => $size);
        if (!$userpicture->visibletoscreenreaders) {
            $attributes['role'] = 'presentation';
            $alt = '';
            $attributes['aria-hidden'] = 'true';
        }

        if (!empty($alt)) {
            $attributes['alt'] = $alt;
            $attributes['title'] = $alt;
        }

        // get the image html output fisrt
        $output = html_writer::empty_tag('img', $attributes);

        // Show fullname together with the picture when desired.
        if ($userpicture->includefullname) {
            $output .= fullname($userpicture->user, $canviewfullnames);
        }

        // then wrap it in link if needed
        if (!$userpicture->link) {
            return $output;
        }

        if (empty($userpicture->courseid)) {
            $courseid = $this->page->course->id;
        } else {
            $courseid = $userpicture->courseid;
        }

        if ($courseid == SITEID) {
            $url = new moodle_url('/user/profile.php', array('id' => $user->id));
        } else {
            $url = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $courseid));
        }

        $attributes = array('href'=>$url);
        if (!$userpicture->visibletoscreenreaders) {
            $attributes['tabindex'] = '-1';
            $attributes['aria-hidden'] = 'true';
        }

        if ($userpicture->popup) {
            $id = html_writer::random_id('userpicture');
            $attributes['id'] = $id;
            $this->add_action_handler(new popup_action('click', $url), $id);
        }

        return html_writer::tag('a', $output, $attributes);
    }