Ad
GetEncryptedData(String) Invokes Inefficient New String(String) Constructor - Findbugs
I'm trying to convert byte[] to String.and its working fine. But FindBugs is pointing me a Minor issue in my code snippet.
code snippet:
//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));
Findbug Report:
getEncryptedData(String) invokes inefficient new String(String) constructor
In which line i'm getting this Error?
encryptedData = new String(Base64.encodeToString(encryptedBytes, Base64.DEFAULT));
Could some one please brief me what is this exactly? And how can we solve this?
Ad
Answer
Replace
encryptedData = new String(Base64.encodeToString(encryptedBytes, Base64.DEFAULT));
with
encryptedData = Base64.encodeToString(encryptedBytes, Base64.DEFAULT);
Encode to String is already returning the string.
Ad
source: stackoverflow.com
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View
Ad