예제 #1
0
def new_key((e, n, d)):
    """Create a RSA object from the given parameters."""
    rsa = m2.rsa_new()
    m2.rsa_set_e(rsa, e)
    m2.rsa_set_n(rsa, n)
    m2.rsa_set_d(rsa, d)
    return RSA.RSA(rsa, 1)
예제 #2
0
def new_key((e, n, d)):
    """Create a RSA object from the given parameters."""
    rsa = m2.rsa_new()
    m2.rsa_set_e(rsa, e)
    m2.rsa_set_n(rsa, n)
    m2.rsa_set_d(rsa, d)
    return RSA.RSA(rsa, 1)
예제 #3
0
    def test_set_e(self):
        rsa = m2.rsa_new()
        m2.rsa_set_e(rsa, b'\000\000\000\003\001\000\001')

        n = m2.rsa_get_n(rsa)
        e = m2.rsa_get_e(rsa)

        self.assertEqual(e, b'\000\000\000\003\001\000\001')
        self.assertEqual(n, b'\x00\x00\x00\x00')
예제 #4
0
    def test_set_n_then_set_e(self):
        rsa = m2.rsa_new()
        m2.rsa_set_n(rsa, b'\000\000\000\004\020\011\006\006')
        m2.rsa_set_e(rsa, b'\000\000\000\003\001\000\001')

        n = m2.rsa_get_n(rsa)
        e = m2.rsa_get_e(rsa)

        self.assertEqual(e, b'\000\000\000\003\001\000\001')
        self.assertEqual(n, b'\000\000\000\004\020\011\006\006')
예제 #5
0
파일: rsa.py 프로젝트: bjornedstrom/toytls
    def __init__(self, n, e):
        self.rsa = None
        self.n = n
        self.e = e

        self.rsa = m2.rsa_new()
        m2.rsa_set_n(self.rsa, num_to_mpi(self.n))
        m2.rsa_set_e(self.rsa, num_to_mpi(self.e))

        self.n_bytes = len(num_to_bytes(self.n))
예제 #6
0
def new_pub_key((e, n)):
    """
    Factory function that instantiates an RSA_pub object from a (e, n) tuple.

    'e' is the RSA public exponent; it is a string in OpenSSL's binary format,
    i.e., a number of bytes in big-endian.

    'n' is the RSA composite of primes; it is a string in OpenSSL's binary format,
    i.e., a number of bytes in big-endian.
    """ 
    rsa = m2.rsa_new()
    m2.rsa_set_e_bin(rsa, e)
    m2.rsa_set_n_bin(rsa, n)
    return RSA_pub(rsa, 1)
예제 #7
0
파일: RSA.py 프로젝트: Bluehorn/M2Crypto
def new_pub_key((e, n)):
    """
    Factory function that instantiates an RSA_pub object from a (e, n) tuple.

    'e' is the RSA public exponent; it is a string in OpenSSL's binary format,
    i.e., a number of bytes in big-endian.

    'n' is the RSA composite of primes; it is a string in OpenSSL's binary format,
    i.e., a number of bytes in big-endian.
    """ 
    import warnings
    warnings.warn('Deprecated. No maintainer for PGP. If you use this, please inform M2Crypto maintainer.', DeprecationWarning)

    rsa = m2.rsa_new()
    m2.rsa_set_e_bin(rsa, e)
    m2.rsa_set_n_bin(rsa, n)
    return RSA_pub(rsa, 1)
예제 #8
0
def new_pub_key(e_n):
    # type: (Tuple[bytes, bytes]) -> RSA_pub
    """
    Instantiate an RSA_pub object from an (e, n) tuple.

    @param e: The RSA public exponent; it is a string in OpenSSL's MPINT
    format - 4-byte big-endian bit-count followed by the appropriate
    number of bits.
    @param n: The RSA composite of primes; it is a string in OpenSSL's MPINT
    format - 4-byte big-endian bit-count followed by the appropriate
    number of bits.
    @return: M2Crypto.RSA.RSA_pub object.
    """
    (e, n) = e_n
    rsa = m2.rsa_new()
    m2.rsa_set_e(rsa, e)
    m2.rsa_set_n(rsa, n)
    return RSA_pub(rsa, 1)
예제 #9
0
def new_pub_key(xxx_todo_changeme):
    """
    Factory function that instantiates an RSA_pub object from a (e, n) tuple.

    'e' is the RSA public exponent; it is a string in OpenSSL's binary format,
    i.e., a number of bytes in big-endian.

    'n' is the RSA composite of primes; it is a string in OpenSSL's binary format,
    i.e., a number of bytes in big-endian.
    """ 
    (e, n) = xxx_todo_changeme
    import warnings
    warnings.warn('Deprecated. No maintainer for PGP. If you use this, please inform M2Crypto maintainer.', DeprecationWarning)

    rsa = m2.rsa_new()
    m2.rsa_set_e_bin(rsa, e)
    m2.rsa_set_n_bin(rsa, n)
    return RSA_pub(rsa, 1)
예제 #10
0
파일: RSA.py 프로젝트: mcepl/M2Crypto
def new_pub_key(e_n):
    # type: (Tuple[bytes, bytes]) -> RSA_pub
    """
    Instantiate an RSA_pub object from an (e, n) tuple.

    :param e: The RSA public exponent; it is a string in OpenSSL's MPINT
              format - 4-byte big-endian bit-count followed by the
              appropriate number of bits.

    :param n: The RSA composite of primes; it is a string in OpenSSL's
              MPINT format - 4-byte big-endian bit-count followed by the
              appropriate number of bits.

    :return: M2Crypto.RSA.RSA_pub object.
    """
    (e, n) = e_n
    rsa = m2.rsa_new()
    m2.rsa_set_en(rsa, e, n)
    return RSA_pub(rsa, 1)
예제 #11
0
파일: keyconvert.py 프로젝트: gnogueras/sfa
def rsa_new_pub_key(couple):
    (e,n)=couple
    rsa = m2.rsa_new()
    m2.rsa_set_e(rsa, e)
    m2.rsa_set_n(rsa, n)
    return RSA_pub_fix(rsa, 1)
예제 #12
0
파일: keyconvert.py 프로젝트: planetlab/sfa
def rsa_new_pub_key(couple):
    (e, n) = couple
    rsa = m2.rsa_new()
    m2.rsa_set_e(rsa, e)
    m2.rsa_set_n(rsa, n)
    return RSA_pub_fix(rsa, 1)