Java 使用ObjectOutputStream发送RSA对象

Java 使用ObjectOutputStream发送RSA对象,java,rsa,objectoutputstream,Java,Rsa,Objectoutputstream,我尝试使用ObjectOutpuStream发送我已完成序列化的RSA自定义对象。为什么ObjectInputStream接收空指针并抛出异常NullPointer,因为没有创建类 import java.io.Serializable; import java.math.BigInteger; import java.security.InvalidKeyException; import java.security.KeyPair; import java.security.KeyPairG

我尝试使用ObjectOutpuStream发送我已完成序列化的RSA自定义对象。为什么ObjectInputStream接收空指针并抛出异常NullPointer,因为没有创建类

import java.io.Serializable;
import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.RSAKeyGenParameterSpec;
import javax.crypto.BadPaddingException;

import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;

public class NewRSA implements Serializable{

   private KeyPair keys ;


   public NewRSA(){
       this.keys=null;
   }
   public NewRSA(KeyPair keys)
   {
       this.keys=keys;
   }
    public KeyPair getKPair()
    {
        return keys;
    }
     public void setKPair(KeyPair keys)
    {
        this.keys=keys;
    }
  public  KeyPair generateRsaKeyPair(int keySize, BigInteger publicExponent)
  {

    try
    {
      KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
      RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(keySize, publicExponent);
      keyGen.initialize(spec);
      keys = keyGen.generateKeyPair();
    }
    catch(Exception e)
    {

    }
    return keys;
  }



    public  byte[] rsaEncrypt(byte[] original, PublicKey key) throws InvalidKeyException, IllegalBlockSizeException, NoSuchAlgorithmException, NoSuchPaddingException, BadPaddingException
  {


      Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
      cipher.init(Cipher.ENCRYPT_MODE, key);
      return cipher.doFinal(original);



  }


  public static byte[] rsaDecrypt(byte[] encrypted, PrivateKey key) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException
  {

      Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
      cipher.init(Cipher.DECRYPT_MODE, key);
      return cipher.doFinal(encrypted);


  }
}
错误是: 没有等级

输出PrintStackTrace java.lang.ClassNotFoundException:com.android.org.conscrypt.OpenSSLRSAPrivateCrtKey 位于java.net.URLClassLoader.findClass(URLClassLoader.java:381) 位于java.lang.ClassLoader.loadClass(ClassLoader.java:424) 位于sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) 位于java.lang.ClassLoader.loadClass(ClassLoader.java:357) 位于java.lang.Class.forName0(本机方法) 位于java.lang.Class.forName(Class.java:348) 位于java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:626) 位于java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1613) 位于java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1518) 位于java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1774) 位于java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351) 位于java.io.ObjectInputStream.readObject(ObjectInputStream.java:371) 位于stefano.Server$ServerThread.attemptLog(Server.java:268) 在stefano.Server$ServerThread.handshake(Server.java:402)
在stefano.Server$ServerThread.run(Server.java:428)

“java.lang.ClassNotFoundException:com.android.org.conscret.OpenSSLRSAPrivateCrtKey”,顺便说一句,这不是
NullPointerException
您应该下载包含该类的项目平台外部密码是的,您是对的。我该如何解决这个问题,请给我一个例子,因为我写了一个java服务器,它从android客户端接收对象序列化类不一定是可移植的,当然从android到Oracle java很可能会崩溃。我也面临同样的问题,你找到解决方案了吗?