Beispiel #1
0
 def loads_private_key(cls, obj):
     curve = cls.DSS_CURVES[obj['crv']]()
     public_numbers = EllipticCurvePublicNumbers(
         base64_to_int(obj['x']),
         base64_to_int(obj['y']),
         curve,
     )
     private_numbers = EllipticCurvePrivateNumbers(base64_to_int(obj['d']),
                                                   public_numbers)
     return private_numbers.private_key(default_backend())
Beispiel #2
0
 def load_private_key(self):
     curve = self.DSS_CURVES[self._dict_data['crv']]()
     public_numbers = EllipticCurvePublicNumbers(
         base64_to_int(self._dict_data['x']),
         base64_to_int(self._dict_data['y']),
         curve,
     )
     private_numbers = EllipticCurvePrivateNumbers(
         base64_to_int(self.tokens['d']), public_numbers)
     return private_numbers.private_key(default_backend())
Beispiel #3
0
    def __init__(self, x, y, d=None, kid=None, curve=None):
        super(EllipticCurveKey, self).__init__()

        self._kid = kid or str(uuid.uuid4())
        self._default_algo = _curve_to_default_algo[curve]
        curve_cls = _kv_crv_to_crypto_cls[curve]

        public_numbers = EllipticCurvePublicNumbers(x, y, curve_cls())
        self._public_key = public_numbers.public_key(default_backend())
        self._private_key = None
        if d is not None:
            private_numbers = EllipticCurvePrivateNumbers(d, public_numbers)
            self._private_key = private_numbers.private_key(default_backend())
    def loads(self, obj):
        for k in ['crv', 'x', 'y']:
            if k not in obj:
                raise ValueError('Not a elliptic curve key')

        curve = self.DSS_CURVES[obj['crv']]()
        public_numbers = EllipticCurvePublicNumbers(
            base64_to_int(obj['x']),
            base64_to_int(obj['y']),
            curve,
        )
        if 'd' in obj:
            private_numbers = EllipticCurvePrivateNumbers(
                base64_to_int(obj['d']), public_numbers)
            return private_numbers.private_key(default_backend())
        return public_numbers.public_key(default_backend())