Java 如何从RSA 1024位加密中获得更短的输出(密文)结果?

Java 如何从RSA 1024位加密中获得更短的输出(密文)结果?,java,encryption,encoding,rsa,Java,Encryption,Encoding,Rsa,我知道RSA加密的输出将等于密钥模的长度(本例中为128字节)。我的RSA加密的代码是: public byte [] RSAEncrypter () throws Exception { byte[] inBytes = textfield1.getString().getBytes(); if (newRSApubKey == null){ throw new Exception("Generate RSA keys first!"); } AsymmetricBl

我知道RSA加密的输出将等于密钥模的长度(本例中为128字节)。我的RSA加密的代码是:

public byte [] RSAEncrypter () throws Exception {
  byte[] inBytes = textfield1.getString().getBytes(); 
  if (newRSApubKey == null){
    throw new Exception("Generate RSA keys first!");
  }
  AsymmetricBlockCipher eng = new RSAEngine();
  eng = new PKCS1Encoding(eng);
  eng.init(true, newRSApubKey);
  return eng.processBlock(inBytes, 0, inBytes.length);
}    
我使用十六进制编码处理结果输出,获得256个字符,如下所示

textfield2.setString(new String(hex.encode(eng.processBlock(inBytes, 0, 
inBytes.length))));
textfield3.setString(new String(Base64.encode(eng.processBlock(inBytes, 0,
inBytes.length))));
我使用base64编码处理相同的输出,获得172个字符,如下所示

textfield2.setString(new String(hex.encode(eng.processBlock(inBytes, 0, 
inBytes.length))));
textfield3.setString(new String(Base64.encode(eng.processBlock(inBytes, 0,
inBytes.length))));

然而,我看到了一个PDF,其中作者能够获得128个字符;尽管他们没有提到这是如何达成的。拜托,我想这是因为使用了编码(对吧?)。我有什么编码选择?或者我该如何处理这行代码以获得至少128个字符的输出?

获得128个字符的唯一方法是将每个字节视为一个字符。在这种情况下,必须允许超出可打印范围的字符,因此必须允许
0x20
7F
以下的所有字符。您可以通过使用C/C++数组来获得这个字符(<代码> char *<代码>或<代码> char []/COD>),并存储长度,因为C不在字符和字节之间分离。所以从这个意义上说,这可能只是一种语言上的混乱