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.mihome.internal;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
@@ -55,13 +55,7 @@ public class EncryptionHelper {
logger.warn("Failed to construct Cipher");
return "";
}
SecretKeySpec keySpec;
try {
keySpec = new SecretKeySpec(key.getBytes("UTF8"), "AES");
} catch (UnsupportedEncodingException e) {
logger.warn("Failed to construct SecretKeySpec");
return "";
}
SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES");
try {
cipher.init(Cipher.ENCRYPT_MODE, keySpec, vector);
} catch (InvalidKeyException | InvalidAlgorithmParameterException e) {