Avoid UnsupportedEncodingException & use const from StandardCharsets (#11948)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
Christoph Weitkamp
2022-01-03 16:05:08 +01:00
committed by GitHub
parent 3f54327d5a
commit 167f8ebc49
52 changed files with 180 additions and 414 deletions

View File

@@ -12,7 +12,7 @@
*/
package org.openhab.binding.miio.internal;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
@@ -99,11 +99,7 @@ public class MiIoCrypto {
SecretKeySpec keySpec = new SecretKeySpec(new byte[16], "AES");
cipher.init(Cipher.DECRYPT_MODE, keySpec);
byte[] decrypted = cipher.doFinal(cipherText);
try {
return new String(decrypted, "UTF-8").trim();
} catch (UnsupportedEncodingException e) {
return new String(decrypted).trim();
}
return new String(decrypted, StandardCharsets.UTF_8).trim();
} catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException
| BadPaddingException e) {
throw new MiIoCryptoException(e.getMessage(), e);