コード例 #1
0
 def value_based_on_content_type(self, value, content_type=None):
     if content_type == self.CT_UNDEFINED:
         raise TypeError('Wrong content type')
     elif content_type == self.CT_STRING:
         return value.decode('utf-8')
     elif content_type == self.CT_JPEG:
         data = base64.b64encode(value).decode('utf-8')
         return 'data:image/jpeg;base64,{0}'.format(data)
     elif content_type == self.CT_DATE:
         return value.decode('utf-8')
     elif content_type == self.CT_PNG:
         data = base64.b64encode(value).decode('utf-8')
         return 'data:image/png;base64,{0}'.format(data)
     return value
コード例 #2
0
 def sign(self, message):
     signature = self.private_key.sign(
         data=message.encode("utf-8"),
         padding=padding.PKCS1v15(),
         algorithm=hashes.SHA256(),
     )
     return base64.b64encode(signature).decode("utf-8")
コード例 #3
0
 def get_public_key(self):
     public_key = self.private_key.public_key()
     der = public_key.public_bytes(
         encoding=serialization.Encoding.DER,
         format=serialization.PublicFormat.SubjectPublicKeyInfo,
     )
     return base64.b64encode(der).decode("utf-8")
コード例 #4
0
ファイル: client.py プロジェクト: MrBurtyyy/yoti-python-sdk
    def __create_request(http_method, path, content):
        if http_method not in HTTP_SUPPORTED_METHODS:
            raise ValueError(
                "{} is not in the list of supported methods: {}".format(
                    http_method, HTTP_SUPPORTED_METHODS))

        request = "{}&{}".format(http_method, path)

        if content is not None:
            b64encoded = base64.b64encode(content)
            b64ascii = b64encoded.decode("ascii")
            request += "&" + b64ascii

        return request
コード例 #5
0
    def __create_request(http_method, path, content):
        """
        Creates a concatenated string that is used in the X-YOTI-AUTH-DIGEST header
        :param http_method:
        :param path:
        :param content:
        :return:
        """

        request = "{}&{}".format(http_method, path)

        if content is not None:
            b64encoded = base64.b64encode(content)
            b64ascii = b64encoded.decode("ascii")
            request += "&" + b64ascii

        return request
コード例 #6
0
ファイル: __main__.py プロジェクト: turbaszek/pyox
         import json
         conf = json.load(json_data)
      app.config['KNOX'] = conf
      app.config['KEY'] = conf.get('key')
      app.config['REDIS_HOST'] = conf.get('redis')
   else:
      app.config.from_object(args.config)
   if args.redis is not None:
      app.config['REDIS_HOST'] = args.redis
   if args.servername is not None:
      app.config['SERVER_NAME'] = args.servername

else:
   #print('Loading from {}'.format(value))
   app.config.from_envvar('WEB_CONF')

if app.config.get('KEY') is None:
   key = app.config.get('KNOX').get('key')
   if key is None:
      from cryptography.fernet import Fernet, base64
      key = base64.b64encode(Fernet.generate_key()).decode('utf-8')
      print('Key generated:')
      print(key)
   app.config['KEY'] = key

if __name__ == '__main__':
   start_task_queue(app)
   app.run()
else:
   start_task_queue(app)
コード例 #7
0
 def base64_content(self):
     data = base64.b64encode(self.__data).decode("utf-8")
     return "data:{0};base64,{1}".format(self.mime_type(), data)