Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 3
0
    def test_set_n(self):
        rsa = m2.rsa_new()
        m2.rsa_set_n(rsa, b'\000\000\000\003\001\000\001')

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

        self.assertEqual(n, b'\000\000\000\003\001\000\001')
        self.assertEqual(e, b'\x00\x00\x00\x00')
Exemplo n.º 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')
Exemplo n.º 5
0
    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))
Exemplo n.º 6
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)
Exemplo n.º 7
0
def new_pub_key(e_n):
    """
    Instantiate an RSA_pub object from an (e, n) tuple.

    @type e: string
    @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.

    @type n: string
    @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.

    @rtype: M2Crypto.RSA.RSA_pub
    @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)
Exemplo n.º 8
0
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)
Exemplo n.º 9
0
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)