:type ciphertext: PreKeyWhisperMessage
776423
def decryptPkmsg(self, ciphertext, textMsg=True):
        
        sessionRecord = self.sessionStore.loadSession(self.recipientId, self.deviceId)
        unsignedPreKeyId = self.sessionBuilder.process(sessionRecord, ciphertext)
        plaintext = self.decryptWithSessionRecord(sessionRecord, ciphertext.getWhisperMessage())

        # callback.handlePlaintext(plaintext)
        self.sessionStore.storeSession(self.recipientId, self.deviceId, sessionRecord)

        if unsignedPreKeyId is not None:
            self.preKeyStore.removePreKey(unsignedPreKeyId)

        return plaintext
1169822
def encrypt(self, plaintext):
        """"""

        # Encrpyt message key.
        msg_key = random_letters(3)
        while msg_key == self.grundstellung:
            msg_key = random_letters(3)
        self.machine.set_display(self.grundstellung)
        enc_key = self.machine.process_text(msg_key)

        # Encrpyt message.
        self.machine.set_display(msg_key)
        ciphertext = self.machine.process_text(plaintext)

        # Encode message with keys.
        return "{enc_key}{ciphertext}{grundstellung}".format(
            enc_key=enc_key,
            ciphertext=ciphertext,
            grundstellung=self.grundstellung
        )
1146746
def get_cipher(data):
    
    legend = {0: 'Use group cipher suite', 1: 'WEP-40', 2: 'TKIP', 4: 'CCMP', 5: 'WEP-104', }
    key = data[3]
    if ieee80211_oui == bytes(data[:3]):
        legend.update({6: 'AES-128-CMAC', 8: 'GCMP', })
    elif ms_oui != bytes(data[:3]):
        key = None
    return legend.get(key, '{0:02x}-{1:02x}-{2:02x}:{3}'.format(data[0], data[1], data[2], data[3]))
225782
def encrypt(clear_text) -> str:
        
        if not isinstance(clear_text, bytes):
            clear_text = str.encode(clear_text)
        cipher = Fernet(current_app.config['KEY'])
        return cipher.encrypt(clear_text).decode("utf-8")
306248
def DecodeMessages(self, response_comms):
    
    # Have we seen this cipher before?
    cipher_verified = False
    try:
      cipher = self.encrypted_cipher_cache.Get(response_comms.encrypted_cipher)
      stats_collector_instance.Get().IncrementCounter(
          "grr_encrypted_cipher_cache", fields=["hits"])

      # Even though we have seen this encrypted cipher already, we should still
      # make sure that all the other fields are sane and verify the HMAC.
      cipher.VerifyReceivedHMAC(response_comms)
      cipher_verified = True

      # If we have the cipher in the cache, we know the source and
      # should have a corresponding public key.
      source = cipher.GetSource()
      remote_public_key = self._GetRemotePublicKey(source)
    except KeyError:
      stats_collector_instance.Get().IncrementCounter(
          "grr_encrypted_cipher_cache", fields=["misses"])
      cipher = ReceivedCipher(response_comms, self.private_key)

      source = cipher.GetSource()
      try:
        remote_public_key = self._GetRemotePublicKey(source)
        if cipher.VerifyCipherSignature(remote_public_key):
          # At this point we know this cipher is legit, we can cache it.
          self.encrypted_cipher_cache.Put(response_comms.encrypted_cipher,
                                          cipher)
          cipher_verified = True

      except UnknownClientCertError:
        # We don't know who we are talking to.
        remote_public_key = None

    # Decrypt the message with the per packet IV.
    plain = cipher.Decrypt(response_comms.encrypted, response_comms.packet_iv)
    try:
      packed_message_list = rdf_flows.PackedMessageList.FromSerializedString(
          plain)
    except rdfvalue.DecodeError as e:
      raise DecryptionError(e)

    message_list = self.DecompressMessageList(packed_message_list)

    # Are these messages authenticated?
    # pyformat: disable
    auth_state = self.VerifyMessageSignature(
        response_comms,
        packed_message_list,
        cipher,
        cipher_verified,
        response_comms.api_version,
        remote_public_key)
    # pyformat: enable

    # Mark messages as authenticated and where they came from.
    for msg in message_list.job:
      msg.auth_state = auth_state
      msg.source = cipher.cipher_metadata.source

    return (message_list.job, cipher.cipher_metadata.source,
            packed_message_list.timestamp)
790091
def _cryptodome_cipher(key, iv):
    
    return AES.new(key, AES.MODE_CFB, iv, segment_size=128)
1116894
def encrypt(plain)
      fail ArgumentError, 'No plain text supplied.' if plain.nil? || plain.empty?

      cipher = self.class.cipher
      cipher.encrypt
      cipher.key = Base64.decode64(@key)
      cipher.iv = iv = cipher.random_iv
      encrypted = cipher.update(plain)
      encrypted << cipher.final

      iv = Base64.strict_encode64(iv)
      encrypted = Base64.strict_encode64(encrypted)

      "$#{iv}$#{encrypted}"
    end
652422
function hashMessage(msg) {
  const sha1 = crypto.createHash('sha1');
  sha1.update(msg);
  return sha1.digest('hex');
}
1121745
async def get_decryption_aes_key(self, key: bytes, material_description: Dict[str, Any]) -> bytes:
        
        if self.private_key is None:
            raise ValueError('Private key not provided during initialisation, cannot decrypt key encrypting key')

        plaintext = await self._loop.run_in_executor(None, lambda: (self.private_key.decrypt(key, padding.PKCS1v15())))

        return plaintext
934633
def crypto_secretbox(message, nonce, key):
    
    if len(key) != crypto_secretbox_KEYBYTES:
        raise exc.ValueError("Invalid key")

    if len(nonce) != crypto_secretbox_NONCEBYTES:
        raise exc.ValueError("Invalid nonce")

    padded = b"\x00" * crypto_secretbox_ZEROBYTES + message
    ciphertext = ffi.new("unsigned char[]", len(padded))

    res = lib.crypto_secretbox(ciphertext, padded, len(padded), nonce, key)
    ensure(res == 0, "Encryption failed", raising=exc.CryptoError)

    ciphertext = ffi.buffer(ciphertext, len(padded))
    return ciphertext[crypto_secretbox_BOXZEROBYTES:]
549069
def as_text(self):
        
        if self.secret_exponent():
            return self.wif()
        sec_hex = self.sec_as_hex()
        if sec_hex:
            return sec_hex
        return self.address()
79792
def get_cipher_key(keyfile=None):
    
    _key = get_key(keyfile)
    _k = md5(_key).hexdigest()
    key = xor(_k[:8], _k[8:16], _k[16:24], _k[24:])
    return key
776910
def decrypt(encrypted)
      fail ArgumentError, 'No cipher text supplied.' if encrypted.nil? || encrypted.empty?

      matches = CIPHER_PATTERN.match(encrypted)

      fail ArgumentError, 'Cipher text has an unsupported format.' if matches.nil?

      cipher = self.class.cipher
      cipher.decrypt
      cipher.key = Base64.decode64(@key)
      cipher.iv = Base64.decode64(matches[1])
      decrypted = cipher.update(Base64.decode64(matches[2]))

      decrypted << cipher.final
    end
762825
def decode_auth_plain(ciphertext)
      message = begin
                  @ecc.ecies_decrypt ciphertext[0,307]
                rescue
                  raise AuthenticationError, $!
                end
      raise RLPxSessionError, 'invalid message length' unless message.size == 194

      sig = message[0,65]
      pubkey = message[65+32,64]
      raise InvalidKeyError, 'invalid initiator pubkey' unless Crypto::ECCx.valid_key?(pubkey)

      nonce = message[65+32+64,32]
      flag = message[(65+32+64+32)..-1].ord
      raise RLPxSessionError, 'invalid flag' unless flag == 0

      [307, sig, pubkey, nonce, 4]
    end
800765
def getCipherText(self, iv, key, plaintext):
        
        cipher = AESCipher(key, iv)
        return cipher.encrypt(bytes(plaintext))
462495
def decode(self, envelope, session, aes_cipher=None, **kwargs):
		
		return WMessengerBytesEnvelope(aes_cipher.decrypt(envelope.message(), decode=False), meta=envelope)
690179
def decode_ack_plain(ciphertext)
      message = begin
                  @ecc.ecies_decrypt ciphertext[0,210]
                rescue
                  raise AuthenticationError, $!
                end
      raise RLPxSessionError, 'invalid message length' unless message.size == 64+32+1

      ephemeral_pubkey = message[0,64]
      nonce = message[64,32]
      known = message[-1].ord
      raise RLPxSessionError, 'invalid known byte' unless known == 0

      [210, ephemeral_pubkey, nonce, 4]
    end