:raises: :class:`RuntimeError` when HMAC verification fails
779668
def symmetric_decrypt_HMAC(cyphertext, key, hmac_secret):
    """"""
    iv = symmetric_decrypt_iv(cyphertext, key)
    message = symmetric_decrypt_with_iv(cyphertext, key, iv)

    hmac = hmac_sha1(hmac_secret, iv[-3:] + message)

    if iv[:13] != hmac[:13]:
        raise RuntimeError("Unable to decrypt message. HMAC does not match.")

    return message
499162
def _generate_appsecret_proof(self):
        
        if six.PY2:
            key = self.appsecret
            message = self.oauth_token
        else:
            key = bytes(self.appsecret, 'utf-8')
            message = bytes(self.oauth_token, 'utf-8')

        return hmac.new(key, message, hashlib.sha256).hexdigest()
559028
function verifyHeader (currentHash, currentHeader, hashPrevBlock, prevHeader, target, isTestnet) {
  try {
    // check hashPrevBlock
    assert.equal(hashPrevBlock, currentHeader.hashPrevBlock)

    try {
      // check difficulty
      assert.equal(currentHeader.bits, target.bits)
      // check hash and target
      assert.equal(isGoodHash(currentHash, target.target), true)

    } catch (err) {
      // special case for testnet:
      // If no block has been found in 20 minutes, the difficulty automatically
      //  resets back to the minimum for a single block, after which it returns
      //  to its previous value.
      if (!(err instanceof assert.AssertionError &&
            isTestnet &&
            currentHeader.time - prevHeader.time > 1200)) {
        throw err
      }

      assert.equal(currentHeader.bits, MAX_BITS)
      assert.equal(isGoodHash(currentHash, MAX_TARGET), true)
    }
  } catch (err) {
    if (err instanceof assert.AssertionError) {
      throw new errors.Blockchain.VerifyHeaderError(currentHash, 'verification failed')
    }

    throw err
  }
}
474621
def verify(api_key = nil)
      raise ConfigurationError, "You must provide an API key to verify" if api_key.nil? && self.api_key.nil?
      perform(:verify, { :providerkey => provider_key, :apikey => api_key || self.api_key }, :get, Success)
    end
969649
def verify(self, data, signature=None, keyrings=None, homedir=None):
        '''
        
        '''

        if isinstance(data, six.text_type):
            data = data.encode('utf-8')

        tmpdir = tempfile.mkdtemp()
        data_file, data_path = tempfile.mkstemp(dir=tmpdir)
        data_file = os.fdopen(data_file, 'wb')
        data_file.write(data)
        data_file.close()
        if signature:
            sig_file, sig_path = tempfile.mkstemp(dir=tmpdir)
            sig_file = os.fdopen(sig_file, 'wb')
            sig_file.write(signature)
            sig_file.close()
        else:
            sig_path = None
        try:
            return self.verify_from_file(
                data_path,
                sig_path=sig_path,
                keyrings=keyrings,
                homedir=homedir
            )
        finally:
            shutil.rmtree(tmpdir)
688428
def _validate(self):
        

        if self._state is not states.INITIAL:
            raise ValueError(obj=self._uid,
                             attribute='state',
                             expected_value=states.INITIAL,
                             actual_value=self._state)

        if not self._executable:
            raise MissingError(obj=self._uid,
                               missing_attribute='executable')
291410
def Verify(self, public_key):
    
    # TODO(amoser): We have to do this manually for now since cryptography does
    # not yet support cert verification. There is PR 2460:
    # https://github.com/pyca/cryptography/pull/2460/files
    # that will add it, once it's in we should switch to using this.

    # Note that all times here are in UTC.
    now = rdfvalue.RDFDatetime.Now().AsDatetime()
    if now > self._value.not_valid_after:
      raise VerificationError("Certificate expired!")
    if now < self._value.not_valid_before:
      raise VerificationError("Certificate not yet valid!")

    public_key.Verify(
        self._value.tbs_certificate_bytes,
        self._value.signature,
        hash_algorithm=self._value.signature_hash_algorithm)
    return True
1248008
def verify(verified_entity, verification_key):
        
        verification = get_object_or_none(Verification, verified_entity=verified_entity)

        if verification is None:
            raise ServerError(VerificationHandler.STATUS_VERIFICATION_NOT_FOUND)
        if not verification.verify(verification_key):
            raise ServerError(VerificationHandler.STATUS_INVALID_VERIFICATION_KEY)

        verification.verified = True
        verification.save()
1175358
private int hmacSignature(byte[] workBytes) {
    try {
      Mac integrityHmac = createMac();
      integrityHmac.init(keys.getIntegrityKey());
      integrityHmac.update(workBytes, PAYLOAD_BASE, workBytes.length - OVERHEAD_SIZE);
      integrityHmac.update(workBytes, INITV_BASE, INITV_SIZE);
      return Ints.fromByteArray(integrityHmac.doFinal());
    } catch (InvalidKeyException e) {
      throw new IllegalStateException(e);
    }
  }
448586
def _check_error_response(self, response, context):
        
        if "error" in response:
            satosa_logging(logger, logging.DEBUG, "%s error: %s %s" %
                           (type(response).__name__, response["error"], response.get("error_description", "")),
                           context.state)
            raise SATOSAAuthenticationError(context.state, "Access denied")
753988
def verify
      create_order
      start_challenge
      wait_verify_status
      check_verify_status
    rescue Acme::Client::Error => e
      retry_on_verify_error(e)
    end
632183
def validate_spki
      unless @spki.is_a?(OpenSSL::ASN1::Sequence)
        raise SPKIError,
              "SPKI data is not an ASN1 sequence (got a #{@spki.class})"
      end

      if @spki.value.length != 2
        raise SPKIError,
              "SPKI top-level sequence must have two elements (length is #{@spki.value.length})"
      end

      alg_id, key_data = @spki.value

      unless alg_id.is_a?(OpenSSL::ASN1::Sequence)
        raise SPKIError,
              "SPKI algorithm_identifier must be a sequence (got a #{alg_id.class})"
      end

      unless (1..2) === alg_id.value.length
        raise SPKIError,
              "SPKI algorithm sequence must have one or two elements (got #{alg_id.value.length} elements)"
      end

      unless alg_id.value.first.is_a?(OpenSSL::ASN1::ObjectId)
        raise SPKIError,
              "SPKI algorithm identifier does not contain an object ID (got #{alg_id.value.first.class})"
      end

      unless key_data.is_a?(OpenSSL::ASN1::BitString)
        raise SPKIError,
              "SPKI publicKeyInfo field must be a BitString (got a #{@spki.value.last.class})"
      end
    end
1289002
def auth(self, encoded):
        
        message, signature = self.split(encoded)
        computed = self.sign(message)
        if not hmac.compare_digest(signature, computed):
            raise AuthenticatorInvalidSignature
916371
def initialize_hmac(self):
        # type: (EncryptionMetadata) -> hmac.HMAC
        
        if self._signkey is not None:
            return hmac.new(self._signkey, digestmod=hashlib.sha256)
        else:
            return None
911368
def hmac_sha256(key, msg):
    

    return hmac.new(key, msg, hashlib.sha256).digest()
520975
def verify(self, secret_key):
        
        verification_input = NotificationMessage.SERVICE_NAME
        verification_input += NotificationMessage.OPERATION_NAME
        verification_input += self.timestamp
        h = hmac.new(key=secret_key, digestmod=sha)
        h.update(verification_input)
        signature_calc = base64.b64encode(h.digest())
        return self.signature == signature_calc
1214266
def validate(key):
    
    if not isinstance(key, (str, bytes)):
        raise KeyError('Key must be of type str or bytes, found type {}'.format(type(key)))