Will return a url safe representation of the state.

        :type encryption_key: Key used for encryption.
        :rtype: str

        :return: Url representation av of the state.
189483
def urlstate(self, encryption_key):
        
        lzma = LZMACompressor()
        urlstate_data = json.dumps(self._state_dict)
        urlstate_data = lzma.compress(urlstate_data.encode("UTF-8"))
        urlstate_data += lzma.flush()
        urlstate_data = _AESCipher(encryption_key).encrypt(urlstate_data)
        lzma = LZMACompressor()
        urlstate_data = lzma.compress(urlstate_data)
        urlstate_data += lzma.flush()
        urlstate_data = base64.urlsafe_b64encode(urlstate_data)
        return urlstate_data.decode("utf-8")
940926
def _secured_storage_parameters(self):
        
        parameters = self._storage_parameters or dict()

        # Handles unsecure mode
        if self._unsecure:
            parameters = parameters.copy()
            parameters['protocol'] = 'http'

        return parameters
881999
def key(self):
        '''  '''
        prefix = type(self).cls_key()

        return '{}:{}:obj'.format(prefix, self.id)
1263925
def encrypt(self):
        
        value = self.parameters.get("Plaintext")
        if isinstance(value, six.text_type):
            value = value.encode('utf-8')
        return json.dumps({"CiphertextBlob": base64.b64encode(value).decode("utf-8"), 'KeyId': 'key_id'})
1284808
def public_key(self):
        
        if self._public_key is None:
            self._public_key = PublicKey.from_point(
                bitcoin_curve.public_key(self.key))
        return self._public_key
790091
def _cryptodome_cipher(key, iv):
    
    return AES.new(key, AES.MODE_CFB, iv, segment_size=128)
672560
def get_iss(self, key):
        
        _state = self.get_state(key)
        if not _state:
            raise KeyError(key)
        return _state['iss']
1361865
def _key(self):
        
        return (
            self._name,
            self._field_type.upper(),
            self._mode.upper(),
            self._description,
            self._fields,
        )
839346
def public_key(self):
        

        if self._public_key is None:
            if self.algorithm == 'ec':
                key = self['private_key'].parsed
                if key['public_key']:
                    self._public_key = key['public_key'].untag()
                else:
                    self._public_key = self._compute_public_key()
            else:
                self._public_key = self._compute_public_key()

        return self._public_key
815148
def entry(bucket, key):
    
    if key is None:
        return urlsafe_base64_encode('{0}'.format(bucket))
    else:
        return urlsafe_base64_encode('{0}:{1}'.format(bucket, key))
1058595
def verify_url(url, secret_key, **kwargs):
    
    result = urlparse(url)
    query_args = MultiValueDict(parse_qs(result.query))
    return verify_url_path(result.path, query_args, secret_key, **kwargs)
520074
def load_pkcs12(self, key):
        
        self.x509 = key.get_certificate().to_cryptography()
        self.public_key = key.get_certificate().to_cryptography().public_key()
        self.private_key = key.get_privatekey().to_cryptography_key()
865359
def encrypt(self, key):
        
        if (self.encrypted):
            return
        # encrypt
        self.iv = Random.new().read(AES.block_size)
        aes = AES.new(key, AES.MODE_CFB, self.iv)
        self.f_key = aes.encrypt(self.f_key)
        self.alpha_key = aes.encrypt(self.alpha_key)
        self.encrypted = True
        # sign
        self.hmac = self.get_hmac(key)
1291746
def marshall_key(self, key):
        
        if key in self.__keys:
            return self.__keys[key]
        skey = pickle.dumps(key, protocol = 0)
        if self.compressKeys:
            skey = zlib.compress(skey, zlib.Z_BEST_COMPRESSION)
        if self.escapeKeys:
            skey = skey.encode('hex')
        if self.binaryKeys:
            skey = buffer(skey)
        self.__keys[key] = skey
        return skey
943005
def hget(self, key):
        
        data = self.r.hget(self.hash, key)
        if data is not None and not isinstance(data, str):
            data = str(self.r.hget(self.hash, key), 'utf-8')
        return data
914713
def todict(self):
        
        return {"f_key": hb_encode(self.f_key),
                "alpha_key": hb_encode(self.alpha_key),
                "chunks": self.chunks,
                "encrypted": self.encrypted,
                "iv": hb_encode(self.iv),
                "hmac": hb_encode(self.hmac)}
1351349
def _key_digest(self, secret_key):
        
        '''
            
        '''
        
        from hashlib import md5, sha256
        from base64 import b64encode
        key_bytes = sha256(secret_key.encode('utf-8')).digest()
        key_b64 = b64encode(key_bytes).decode()
        digest_bytes = md5(key_bytes).digest()
        digest_b64 = b64encode(digest_bytes).decode()
        
        return key_b64, digest_b64