Example #1
0
File: jwt.py Project: almet/PyVEP
 def __init__(self, data):
     e = int2mpint(int(data["e"]))
     n = int2mpint(int(data["n"]))
     try:
         d = int2mpint(int(data["d"]))
     except KeyError:
         self.rsa = _RSA.new_pub_key((e, n))
     else:
         self.rsa = _RSA.new_key((e, n, d))
Example #2
0
 def __init__(self, data):
     e = int2mpint(int(data["e"]))
     n = int2mpint(int(data["n"]))
     try:
         d = int2mpint(int(data["d"]))
     except KeyError:
         self.rsa = _RSA.new_pub_key((e, n))
     else:
         self.rsa = _RSA.new_key((e, n, d))
Example #3
0
def get_crypto_obj(algo, filename=None, key=None):
    if filename is None and key is None:
        raise ValueError('you need to specify either filename or key')

    if key is not None:
        bio = BIO.MemoryBuffer(str(key))
    else:
        bio = BIO.openfile(filename)

    # we can know what's the algorithm used thanks to the filename
    if algo.startswith('RS'):
        obj = _RSA.load_pub_key_bio(bio)
    elif algo.startswith('DS'):
        obj = _DSA.load_pub_key_bio(bio)
    else:
        raise ValueError('unknown algorithm')
    return obj