我目前正试图用RSA加密用户输入数据(我知道这不是最好的方法,但它适用于赋值,我需要这样做),我让它加密和解密小串数据,但现在正试图通过在每个字处拆分字符串来处理任意长度的数据,但是当我试图以这种方式加密数据时,会出现一个错误,上面写着“不兼容类型: byte[]不能转换为字节”。
我不知道为什么会发生这种事,也不知道如何解决。任何帮助都是很棒的,所以即使是一个关于如何以不同的方式来做这件事的想法。
final String originalText = "New Class NewClass NewClass NewClass ";
String[] splited = originalText.split("\\s+");
ObjectInputStream inputStream = null;
// Encrypt the string using the public key
inputStream = new ObjectInputStream(new FileInputStream(PUBLIC_KEY_FILE));
final PublicKey publicKey = (PublicKey) inputStream.readObject();
final byte[] cipherText = null;
for (int i = 0; i < splited.length; i++) {
LINE ERROR APPEARS ON
cipherText[i] = encrypt(splited[i], publicKey);
System.out.println(cipherText[i]);
}发布于 2014-03-06 17:59:55
调用encrypt之后,您将得到字节数组,因此您的cipherText可以是byte[][] cipherText,然后要查看它,只需调用System.out.println(new String(cipherText[i]));
引发编辑 NPE是因为您没有初始化cipherText数组。请试用以下方法:
byte[][] cipherText = new byte[splited.length][];https://stackoverflow.com/questions/22232313
复制相似问题