Decrypt and unpack the original OpenConfig object,
        serialized using MessagePack.
        Raise BadSignatureException when the signature
        was forged or corrupted.
545993
def decrypt(self, binary):
        '''
        
        '''
        try:
            encrypted = self.verify_key.verify(binary)
        except BadSignatureError:
            log.error('Signature was forged or corrupt', exc_info=True)
            raise BadSignatureException('Signature was forged or corrupt')
        try:
            packed = self.priv_key.decrypt(encrypted)
        except CryptoError:
            log.error('Unable to decrypt', exc_info=True)
            raise CryptoException('Unable to decrypt')
        return umsgpack.unpackb(packed)
245744
@Deprecated
    public Cipher decrypt() {
        try {
            Cipher cipher = Secret.getCipher(KEY_ALGORITHM);
            cipher.init(Cipher.DECRYPT_MODE, getKey());
            return cipher;
        } catch (GeneralSecurityException e) {
            throw new AssertionError(e);
        }
    }
223844
def unwrap(self, message, signature):
        
        plain_text = _Ntlm2Session.decrypt(self, message)
        _Ntlm2Session.verify(self, plain_text, signature)
        return plain_text
625194
def decrypt(self, message):
        

        # Unserialize the encrypted message
        message = json.loads(message)

        # Set up a list for the unencrypted lines of the message
        unencrypted_msg = []

        for line in message:

            # Convert from ascii back to bytestring
            enc_line = binascii.a2b_base64(line)

            # Decrypt the line using our private key
            unencrypted_line = rsa.decrypt(enc_line, self.private_key)

            unencrypted_msg.append(unencrypted_line)

        # Convert the message from a list back into a string
        unencrypted_msg = "".join(unencrypted_msg)

        return unencrypted_msg
1346599
def decode(self):
        

        fmt, len_low, len_high, device_id, report_id, sent_timestamp, signature_flags, \
        origin_streamer, streamer_selector = unpack("<BBHLLLBBH", self.raw_report[:20])

        assert fmt == 1
        length = (len_high << 8) | len_low

        self.origin = device_id
        self.report_id = report_id
        self.sent_timestamp = sent_timestamp
        self.origin_streamer = origin_streamer
        self.streamer_selector = streamer_selector
        self.signature_flags = signature_flags

        assert len(self.raw_report) == length

        remaining = self.raw_report[20:]
        assert len(remaining) >= 24
        readings = remaining[:-24]
        footer = remaining[-24:]

        lowest_id, highest_id, signature = unpack("<LL16s", footer)
        signature = bytearray(signature)

        self.lowest_id = lowest_id
        self.highest_id = highest_id
        self.signature = signature

        signed_data = self.raw_report[:-16]
        signer = ChainedAuthProvider()

        if signature_flags == AuthProvider.NoKey:
            self.encrypted = False
        else:
            self.encrypted = True

        try:
            verification = signer.verify_report(device_id, signature_flags, signed_data, signature,
                                                report_id=report_id, sent_timestamp=sent_timestamp)
            self.verified = verification['verified']
        except NotFoundError:
            self.verified = False

        # If we were not able to verify the report, do not try to parse or decrypt it since we
        # can't guarantee who it came from.
        if not self.verified:
            return [], []

        # If the report is encrypted, try to decrypt it before parsing the readings
        if self.encrypted:
            try:
                result = signer.decrypt_report(device_id, signature_flags, readings,
                                               report_id=report_id, sent_timestamp=sent_timestamp)
                readings = result['data']
            except NotFoundError:
                return [], []

        # Now parse all of the readings
        # Make sure this report has an integer number of readings
        assert (len(readings) % 16) == 0

        time_base = self.received_time - datetime.timedelta(seconds=sent_timestamp)
        parsed_readings = []

        for i in range(0, len(readings), 16):
            reading = readings[i:i+16]
            stream, _, reading_id, timestamp, value = unpack("<HHLLL", reading)

            parsed = IOTileReading(timestamp, stream, value, time_base=time_base, reading_id=reading_id)
            parsed_readings.append(parsed)

        return parsed_readings, []
477226
def extract_self_cert(signed_raw: str) -> Identity:
        
        lines = signed_raw.splitlines(True)
        n = 0

        version = int(Revocation.parse_field("Version", lines[n]))
        n += 1

        Revocation.parse_field("Type", lines[n])
        n += 1

        currency = Revocation.parse_field("Currency", lines[n])
        n += 1

        issuer = Revocation.parse_field("Issuer", lines[n])
        n += 1

        unique_id = Revocation.parse_field("IdtyUniqueID", lines[n])
        n += 1

        timestamp = Revocation.parse_field("IdtyTimestamp", lines[n])
        n += 1

        signature = Revocation.parse_field("IdtySignature", lines[n])
        n += 1

        return Identity(version, currency, issuer, unique_id, timestamp, signature)
919319
def decrypt(self):
        
        if not self._crypter:
            return b''
        try:
            plaintext = self._crypter.decrypt(self._ciphertext, **self._decrypt_params)
            return plaintext
        except Exception as e:
            exc_info = sys.exc_info()
            six.reraise(
                ValueError('Invalid ciphertext "%s", error: %s' % (self._ciphertext, e)),
                None,
                exc_info[2]
            )
310117
private void readSigningKeyAndCertificate(Configuration conf) throws OfficeWriterException, IOException {
	if ((this.howc.getSigKeystoreFile()!=null) && (!"".equals(this.howc.getSigKeystoreFile()))) {
		LOG.info("Signing document");
		if ((this.howc.getSigKeystoreAlias()==null) || ("".equals(this.howc.getSigKeystoreAlias()))) {
				LOG.error("Keystore alias for signature keystore not defined. Cannot sign document");
				throw new OfficeWriterException("Keystore alias for signature keystore not defined. Cannot sign document");
		}
		if ((this.howc.getSigKeystoreType()==null) || ("".equals(this.howc.getSigKeystoreType()))) {
			LOG.error("Keystore type for signature keystore not defined. Cannot sign document");
			throw new OfficeWriterException("Keystore type for signature keystore not defined. Cannot sign document");
		}
		LOG.info("Reading keystore");
		HadoopKeyStoreManager hksm = new HadoopKeyStoreManager(conf);
		try {
			hksm.openKeyStore(new Path(this.howc.getSigKeystoreFile()), this.howc.getSigKeystoreType(), this.howc.getSigKeystorePassword());
			this.howc.setSigKey(hksm.getPrivateKey(this.howc.getSigKeystoreAlias(), this.howc.getSigKeystorePassword()));
			this.howc.setSigCertificate((X509Certificate) hksm.getCertificate(this.howc.getSigKeystoreAlias()));
		} catch (NoSuchAlgorithmException | CertificateException | KeyStoreException | IllegalArgumentException | UnrecoverableKeyException  e) {
			LOG.error("Cannopt read signing certificate. Exception: ",e);
			throw new OfficeWriterException("Cannot read keystore to obtain key and certificate for signing "+e);
		}
		
		
	}
}
640649
def extract_signed_data(digsig)
            # Computes the boundaries of the Contents field.
            start_sig = digsig[:Contents].file_offset

            stream = StringScanner.new(self.original_data)
            stream.pos = digsig[:Contents].file_offset
            Object.typeof(stream).parse(stream)
            end_sig = stream.pos
            stream.terminate

            r1, r2 = digsig.ranges
            if r1.begin != 0 or
                r2.end != self.original_data.size or
                r1.end != start_sig or
                r2.begin != end_sig

                raise SignatureError, "Invalid signature byte range"
            end

            self.original_data[r1] + self.original_data[r2]
        end
1266376
def sign(self, encoded):
        
        signature = self._hmac.copy()
        signature.update(encoded)
        return signature.hexdigest().encode('utf-8')
1159837
def unpack(d):
    
    p = SBP._parser.parse(d)
    assert p.preamble == SBP_PREAMBLE, "Invalid preamble 0x%x." % p.preamble
    return SBP(p.msg_type, p.sender, p.length, p.payload, p.crc)
330758
def crypto_sign_open(signed, pk):
    
    message = ffi.new("unsigned char[]", len(signed))
    message_len = ffi.new("unsigned long long *")

    if lib.crypto_sign_open(
            message, message_len, signed, len(signed), pk) != 0:
        raise exc.BadSignatureError("Signature was forged or corrupt")

    return ffi.buffer(message, message_len[0])[:]
155628
def from_signed_raw(cls: Type[RevocationType], signed_raw: str) -> RevocationType:
        
        lines = signed_raw.splitlines(True)
        n = 0

        version = int(Revocation.parse_field("Version", lines[n]))
        n += 1

        Revocation.parse_field("Type", lines[n])
        n += 1

        currency = Revocation.parse_field("Currency", lines[n])
        n += 1

        issuer = Revocation.parse_field("Issuer", lines[n])
        n += 1

        identity_uid = Revocation.parse_field("IdtyUniqueID", lines[n])
        n += 1

        identity_timestamp = Revocation.parse_field("IdtyTimestamp", lines[n])
        n += 1

        identity_signature = Revocation.parse_field("IdtySignature", lines[n])
        n += 1

        signature = Revocation.parse_field("Signature", lines[n])
        n += 1

        identity = Identity(version, currency, issuer, identity_uid, identity_timestamp, identity_signature)

        return cls(version, currency, identity, signature)
211857
def _split_raw_signature(sig):
        
        c_length = len(sig) // 2
        r = int_from_bytes(sig[:c_length], byteorder='big')
        s = int_from_bytes(sig[c_length:], byteorder='big')
        return r, s
536196
def _api_decrypt():
    '''
    
    '''
    kms = _kms()
    data_key = _cfg_data_key()
    try:
        return kms.decrypt(CiphertextBlob=data_key)
    except botocore.exceptions.ClientError as orig_exc:
        error_code = orig_exc.response.get('Error', {}).get('Code', '')
        if error_code != 'InvalidCiphertextException':
            raise
        err_msg = 'aws_kms:data_key is not a valid KMS data key'
        config_error = salt.exceptions.SaltConfigurationError(err_msg)
        six.raise_from(config_error, orig_exc)
578452
def authenticate(self, req_data, identifier: Optional[str]=None,
                     signature: Optional[str]=None, threshold: Optional[int] = None,
                     verifier: Verifier=DidVerifier):
        
        to_serialize = {k: v for k, v in req_data.items()
                        if k not in self.excluded_from_signing}
        if req_data.get(f.SIG.nm) is None and \
                req_data.get(f.SIGS.nm) is None and \
                signature is None:
            raise MissingSignature
        if req_data.get(f.IDENTIFIER.nm) and (req_data.get(f.SIG.nm) or
                                              signature):
            try:
                # if not identifier:
                identifier = identifier or self._extract_identifier(req_data)

                # if not signature:
                signature = signature or self._extract_signature(req_data)

                signatures = {identifier: signature}
            except Exception as ex:
                if ex in (MissingSignature, EmptySignature, MissingIdentifier,
                          EmptyIdentifier):
                    ex = ex(req_data.get(f.IDENTIFIER.nm), req_data.get(f.SIG.nm))
                raise ex
        else:
            signatures = req_data.get(f.SIGS.nm, None)
        return self.authenticate_multi(to_serialize, signatures=signatures,
                                       threshold=threshold, verifier=verifier)
727413
def deconstruct(self):
        
        name, path, args, kwargs = super(BaseEncryptedField, self).deconstruct()
        kwargs.update({
            #'key': self.cipher_key,
            'cipher': self.cipher_name,
            'charset': self.charset,
            'check_armor': self.check_armor,
            'versioned': self.versioned,
        })
        return name, path, args, kwargs