def encrypt(self, key, iv="", cek="", **kwargs): """ :param key: Shared symmetric key :param iv: initialization vector :param cek: :param kwargs: Extra keyword arguments, just ignore for now. :return: """ _msg = self.msg _args = self._dict try: _args["kid"] = kwargs["kid"] except KeyError: pass jwe = JWEnc(**_args) # If no iv and cek are given generate them cek, iv = self._generate_key_and_iv(self["enc"], cek, iv) if isinstance(key, six.string_types): kek = key else: kek = intarr2str(key) # The iv for this function must be 64 bit # Which is certainly different from the one above jek = aes_wrap_key(kek, cek) _enc = self["enc"] ctxt, tag, cek = self.enc_setup(_enc, _msg, jwe.b64_encode_header(), cek, iv=iv) return jwe.pack(parts=[jek, iv, ctxt, tag])
def encrypt(self, key, iv="", cek=""): """ :param key: Shared symmetric key :param iv: :param cek: :return: """ _msg = self.msg b64_header = self._encoded_header() cek, iv = self._generate_key_and_iv(self["enc"], cek, iv) if isinstance(key, basestring): kek = key else: kek = intarr2str(key) # The iv for this function must be 64 bit # Which is certainly different from the one above jek = aes_wrap_key(kek, cek) auth_data = b64_header _enc = self["enc"] ctxt, tag, cek = self.enc_setup(_enc, _msg, auth_data, cek, iv=iv) return self.pack(b64_header, jek, iv, ctxt, tag)
def encrypt(self, key, iv="", cek="", **kwargs): """ :param key: Shared symmetric key :param iv: initialization vector :param cek: :param kwargs: Extra keyword arguments, just ignore for now. :return: """ _msg = self.msg _args = {} try: _args["kid"] = kwargs["kid"] except KeyError: pass b64_header = self._encoded_header(_args) # If no iv and cek are given generate them cek, iv = self._generate_key_and_iv(self["enc"], cek, iv) if isinstance(key, basestring): kek = key else: kek = intarr2str(key) # The iv for this function must be 64 bit # Which is certainly different from the one above jek = aes_wrap_key(kek, cek) auth_data = b64_header _enc = self["enc"] ctxt, tag, cek = self.enc_setup(_enc, _msg, auth_data, cek, iv=iv) return self.pack(b64_header, jek, iv, ctxt, tag)
def encrypt(self, key, iv="", cek="", **kwargs): """ :param key: Shared symmetric key :param iv: initialization vector :param cek: :param kwargs: Extra keyword arguments, just ignore for now. :return: """ _msg = self.msg _args = self._dict try: _args["kid"] = kwargs["kid"] except KeyError: pass jwe = JWEnc(**_args) # If no iv and cek are given generate them cek, iv = self._generate_key_and_iv(self["enc"], cek, iv) if isinstance(key, SYMKey): try: kek = key.key.encode('utf8') except AttributeError: kek = key.key elif isinstance(key, six.binary_type): kek = key else: kek = intarr2str(key) # The iv for this function must be 64 bit # Which is certainly different from the one above jek = aes_wrap_key(kek, cek) _enc = self["enc"] ctxt, tag, cek = self.enc_setup(_enc, _msg.encode(), jwe.b64_encode_header(), cek, iv=iv) return jwe.pack(parts=[jek, iv, ctxt, tag])