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)
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')
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')
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))
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)
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)
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)
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)
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)
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)
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)