Create a signature

@see self::verify()
@access public
@param string $message
@return string
164031
function sign($message)
    {
        if (empty($this->modulus) || empty($this->exponent)) {
            return false;
        }

        switch ($this->signatureMode) {
            case self::SIGNATURE_PKCS1:
                return $this->_rsassa_pkcs1_v1_5_sign($message);
            //case self::SIGNATURE_PSS:
            default:
                return $this->_rsassa_pss_sign($message);
        }
    }
695241
private function createMessage($message)
    {
        if ($message instanceof Message) {
            return $message;
        }

        if ($message instanceof Template) {
            $message = new Attachment(Attachment::TYPE_TEMPLATE, $message);
        }

        if (is_string($message) || $message instanceof Attachment) {
            return new Message($message);
        }

        throw new \InvalidArgumentException('$message should be a string, Message, Attachment or Template');
    }
1198727
def verify(self, message, signature):
        
        # Parse the signature header
        mac = _Ntlm2MessageSignature()
        mac.from_string(signature)

        # validate the sequence
        if mac['sequence'] != self.incoming_sequence:
            raise Exception("The message was not received in the correct sequence.")

        # extract the supplied checksum
        checksum = struct.pack('<q', mac['checksum'])
        if self.key_exchange:
            checksum = self.incoming_seal.update(checksum)

        # calculate the expected checksum for the message
        hmac_context = hmac.new(self.incoming_signing_key)
        hmac_context.update(struct.pack('<i', self.incoming_sequence) + message)
        expected_checksum = hmac_context.digest()[:8]

        # validate the supplied checksum is correct
        if checksum != expected_checksum:
            raise Exception("The message has been altered")

        #logger.debug("Verify Sequence Number: %s", AsHex(self.outgoing_sequence))
        self.incoming_sequence += 1
619696
public static function sign(RSAKey $key, $message, $hash)
    {
        Assertion::string($message);
        Assertion::string($hash);
        Assertion::inArray($hash, ['sha256', 'sha384', 'sha512']);
        $em = self::encodeEMSAPSS($message, 8 * $key->getModulusLength() - 1, Hash::$hash());
        Assertion::string($em);
        $message = self::convertOctetStringToInteger($em);
        $signature = self::getRSASP1($key, $message);
        Assertion::isInstanceOf($signature, BigInteger::class);

        return self::convertIntegerToOctetString($signature, $key->getModulusLength());
    }
918354
public function decryptMessage($message)
    {
        $calgo = $this->config->getCipherAlgorithm();
        $cmode = $this->config->getCipherMode();
        $malgo = $this->config->getHmacAlgorithm();
        
        $size = mcrypt_get_iv_size($calgo, $cmode);
        $keySize = mcrypt_get_key_size($calgo, $cmode);
        $hmacSize = strlen(hash_hmac($malgo, '', 'foo-key', true));

        $cmac = substr($message, -1 * $hmacSize);
        $iv = substr($message, 0, $size);
        $cipherText = substr($message, $size, -1 * $hmacSize);
        $hmac = hash_hmac($malgo, $iv . $cipherText, $this->computeCipherKey($this->config->getHmacKey(), $hmacSize, $iv), true);
        
        if(!SecurityUtil::timingSafeEquals($hmac, $cmac))
        {
            throw new IntegrityCheckFailedException('Invalid encrypted input message detected');
        }
        
        $key = $this->computeCipherKey($this->config->getCipherKey(), $keySize, $iv);
        $data = mcrypt_decrypt($calgo, $key, $cipherText, $cmode, $iv);
        
        // PKCS7 Padding
        $pad = ord($data[strlen($data) - 1]);
        $data = substr($data, 0, -1 * $pad);
        
        // Remove zero-byte padding from the string.
        return $data;
    }
723078
public function message($message=null) {
        if(is_null($message)) {
            return $this->message;
        }
        $this->message = $message;
    }
690021
public static function createMime(string $message, string $signature): string {
        $message = file_get_contents($message);
        $signature = file_get_contents($signature);
        if(!ctype_print($signature)) {
            $signature = chunk_split(base64_encode($signature), 64, "\n");
        }
        $result[] = 'MIME-Version: 1.0';
        $result[] = 'Content-Type: multipart/signed; protocol="application/x-pkcs7-signature"; micalg="sha1"; boundary="----514017AE3B7DB78049DEB1F0D4599106"';
        $result[] = '';
        $result[] = 'This is an S/MIME signed message';
        $result[] = '';
        $result[] = '------514017AE3B7DB78049DEB1F0D4599106';
        $result[] = $message;
        $result[] = '------514017AE3B7DB78049DEB1F0D4599106';
        $result[] = 'Content-Type: application/x-pkcs7-signature; name="smime.p7s"';
        $result[] = 'Content-Transfer-Encoding: base64';
        $result[] = 'Content-Disposition: attachment; filename="smime.p7s"';
        $result[] = '';
        $result[] = $signature;
        $result[] = '------514017AE3B7DB78049DEB1F0D4599106--';
        return implode("\n", $result);
    }
434867
protected function hash($message)
    {
        $hash = hash_hmac(
            'sha256',
            $message,
            $this->appClientSecret,
            true
        );

        return base64_encode($hash);
    }
241663
protected function isValidMessage($message): Message
    {
        if ($message instanceof Message) {
            return $message;
        }

        if (\is_string($message) || $message instanceof Attachment) {
            return Message::create($message);
        }

        throw new MessengerException(sprintf(
            'message must be a string or an instance of %s or %s.',
            Message::class,
            Attachment::class
        ));
    }
1009665
public function write($message)
    {
        $written = false;

        if ($this->output_allowed) {
            $written = error_log($message);
        }

        return $written;
    }
1076357
function verify($text, $signature)
    {
        try {
            $verified = $this->gpg->verify($text, $signature);
            return $this->parse_signature($verified[0]);
        }
        catch (Exception $e) {
            return $this->get_error_from_exception($e);
        }
    }
1073220
private function createExceptionMessage($message)
    {
        $parameters = $this->parameters;

        if ($parameters->scheme === 'unix') {
            return "$message [$parameters->scheme:$parameters->path]";
        }

        if (filter_var($parameters->host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
            return "$message [$parameters->scheme://[$parameters->host]:$parameters->port]";
        }

        return "$message [$parameters->scheme://$parameters->host:$parameters->port]";
    }
1260930
function _makePairs($message)
    {
        $signed = $message->getArg(Auth_OpenID_OPENID_NS, 'signed');
        if (!$signed || Auth_OpenID::isFailure($signed)) {
            // raise ValueError('Message has no signed list: %s' % (message,))
            return null;
        }

        $signed_list = explode(',', $signed);
        $pairs = array();
        $data = $message->toPostArgs();
        foreach ($signed_list as $field) {
            $pairs[] = array($field, Auth_OpenID::arrayGet($data,
                                                           'openid.' .
                                                           $field, ''));
        }
        return $pairs;
    }
1157781
public function sign(Message $message): Message
    {
        if (!$this->serverKeyFingerprint) {
            throw new GPGMailerException('No signing key provided');
        }
        $gnupg = new \Crypt_GPG($this->options);
        $gnupg->addSignKey($this->serverKeyFingerprint);

        try {
            return (clone $message)->setBody(
                $gnupg->sign(
                    $message->getBodyText(),
                    \Crypt_GPG::SIGN_MODE_CLEAR,
                    true
                )
            );
        } catch (\PEAR_Exception $ex) {
            throw new GPGMailerException(
                'Could not sign message: ' . $ex->getMessage(),
                $ex->getCode(),
                $ex
            );
        }
    }
684439
public function message(string $message)
    {
        $this->_validations[\count($this->_validations) - 1]['message'] = $message;

        return $this;
    }
341784
public function signMessage(Swift_Message $message)
    {
        if (null === $this->signCertificate && null === $this->encryptCert) {
            return $this;
        }

        if ($this->signThenEncrypt) {
            $this->smimeSignMessage($message);
            $this->smimeEncryptMessage($message);
        } else {
            $this->smimeEncryptMessage($message);
            $this->smimeSignMessage($message);
        }
    }
61765
public function commitMsgHook($message) {
    $this->say('Validating commit message syntax...');
    $pattern = $this->getConfigValue('git.commit-msg.pattern');
    $help_description = $this->getConfigValue('git.commit-msg.help_description');
    $example = $this->getConfigValue('git.commit-msg.example');
    $this->logger->debug("Validing commit message with regex <comment>$pattern</comment>.");
    if (!preg_match($pattern, $message)) {
      $this->logger->error("Invalid commit message!");
      $this->say("Commit messages must conform to the regex $pattern");
      if (!empty($help_description)) {
        $this->say("$help_description");
      }
      if (!empty($example)) {
        $this->say("Example: $example");
      }
      $this->logger->notice("To disable or customize Git hooks, see http://blt.rtfd.io/en/latest/readme/extending-blt/#git-hooks");

      return 1;
    }

    return 0;
  }