Ejemplo n.º 1
0
 def getPublicKey(self, format='JWK'):
     """
     Return public key as a PEM or JWK string or as a JCS/JWK in an JSONObjectWriter
     """
     if exportFormatCheck(format) == 'PEM':
         if self.isRSA():
             return exportPublicKeyAsPem(self.nativePrivateKey.publickey())
         return exportPublicKeyAsPem(
             self.nativePrivateKey.get_verifying_key())
     publicKey = JSONObjectWriter()
     if self.isRSA():
         publicKey.setString('kty', 'RSA')
         publicKey.setCryptoBigNum('n', self.nativePrivateKey.n)
         publicKey.setCryptoBigNum('e', self.nativePrivateKey.e)
     else:
         publicKey.setString('kty', 'EC')
         publicKey.setString('crv', getEcCurveName(self.nativePrivateKey))
         point = self.nativePrivateKey.get_verifying_key().to_string()
         length = len(point)
         if length % 2:
             raise ValueError('EC point length error')
         length >>= 1
         publicKey.setBinary('x', point[:length])
         publicKey.setBinary('y', point[length:])
     if format == 'JWK':
         return publicKey.serialize()
     return publicKey
Ejemplo n.º 2
0
 def getPublicKey(self, format='JWK'):
     """
     Return public key as a PEM or JWK string or as a JCS in an JSONObjectWriter
     """
     if exportFormatCheck(format) == 'PEM':
         return exportPublicKeyAsPem(self.nativePublicKey)
     if format == 'JWK':
         return serializeJson(self.publicKey)
     return JSONObjectWriter(self.publicKey)
 def getPublicKey(self, format='JWK'):
     """
     Return public key as a PEM or JWK string or as a JCS in an JSONObjectWriter
     """
     if exportFormatCheck(format) == 'PEM':
         return exportPublicKeyAsPem(self.nativePublicKey)
     if format == 'JWK':
         jwk = OrderedDict()
         for item in self.publicKey:
             key = item
             if key == 'type':
                 key = 'kty'
             elif key == 'curve':
                 key = 'crv'
             jwk[key] = self.publicKey[item]
         return serializeJson(jwk)
     return JSONObjectWriter(self.publicKey)
Ejemplo n.º 4
0
 def getPublicKey(self,format='JWK'):
     """
     Return public key as a PEM or JWK string or as a JCS in an JSONObjectWriter
     """
     if exportFormatCheck(format) == 'PEM':
         return exportPublicKeyAsPem(self.nativePublicKey)
     if format == 'JWK':
         jwk = OrderedDict()
         for item in self.publicKey:
             key = item
             if key == 'type':
                 key = 'kty'
             elif key == 'curve':
                 key = 'crv'
             jwk[key] = self.publicKey[item]
         return serializeJson(jwk)
     return JSONObjectWriter(self.publicKey)