code: def exportpriv(self, format="PEM", password=None, cipher=None):
          
          bio = Membio()
          if cipher is None:
              evp_cipher = None
          else:
              evp_cipher = cipher.cipher
          if format == "PEM":
              ret = libcrypto.PEM_write_bio_PrivateKey(bio.bio, self.key,
                                           evp_cipher, None, 0,
                                           _password_callback(password),
                                           None)
              if ret ==0:
                  raise PKeyError("error serializing private key")
              return str(bio)
          else:
              ret = libcrypto.i2d_PKCS8PrivateKey_bio(bio.bio, self.key,
                                                 evp_cipher, None, 0,
                                                _password_callback(password),
                                                 None)
              if ret ==0:
                  raise PKeyError("error serializing private key")
              return bintype(bio)
docs: Returns private key as PEM or DER Structure.
          If password and cipher are specified, encrypts key
          on given password, using given algorithm. Cipher must be
          an ctypescrypto.cipher.CipherType object
  
          Password can be either string or function with one argument,
          which returns password. It is called with argument True, which
          means, that we are encrypting key, and password should be
          verified (requested twice from user, for example).