getEncryptedData(String) 调用低效的 new String(String) 构造函数 - Findbugs

getEncryptedData(String) invokes inefficient new String(String) constructor - Findbugs

我正在尝试将 byte[] 转换为 String.and,它工作正常。但是 FindBugs 在我的代码片段中指出了一个小问题。

代码片段:

        //Encrypt the data withe public key.
        Cipher cipher = Cipher.getInstance(TRASFORMATION);
        cipher.init(Cipher.ENCRYPT_MODE, publicKey);
        byte[] encryptedBytes = cipher.doFinal(data.getBytes(StandardCharsets.UTF_8));
        encryptedData = new String(Base64.encodeToString(encryptedBytes, Base64.DEFAULT));

查找错误报告:

getEncryptedData(String) 调用低效的 new String(String) 构造函数

我在哪一行收到这个错误?

encryptedData = new String(Base64.encodeToString(encryptedBytes, Base64.DEFAULT));

谁能简单介绍一下这到底是什么?我们如何解决这个问题?

替换

encryptedData = new String(Base64.encodeToString(encryptedBytes, Base64.DEFAULT));

encryptedData = Base64.encodeToString(encryptedBytes, Base64.DEFAULT);

编码为字符串已经返回字符串。