diff --git a/app/src/main/java/com/beemdevelopment/aegis/crypto/CryptoUtils.java b/app/src/main/java/com/beemdevelopment/aegis/crypto/CryptoUtils.java index 0a4fd93b..e4b12230 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/crypto/CryptoUtils.java +++ b/app/src/main/java/com/beemdevelopment/aegis/crypto/CryptoUtils.java @@ -6,7 +6,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.CharBuffer; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; @@ -122,7 +122,7 @@ public class CryptoUtils { private static byte[] toBytes(char[] chars) { CharBuffer charBuf = CharBuffer.wrap(chars); - ByteBuffer byteBuf = Charset.forName("UTF-8").encode(charBuf); + ByteBuffer byteBuf = StandardCharsets.UTF_8.encode(charBuf); return byteBuf.array(); } } diff --git a/app/src/main/java/com/beemdevelopment/aegis/db/DatabaseFile.java b/app/src/main/java/com/beemdevelopment/aegis/db/DatabaseFile.java index 71b2cd49..f99006eb 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/db/DatabaseFile.java +++ b/app/src/main/java/com/beemdevelopment/aegis/db/DatabaseFile.java @@ -12,7 +12,7 @@ import com.beemdevelopment.aegis.encoding.HexException; import org.json.JSONException; import org.json.JSONObject; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; public class DatabaseFile { public static final byte VERSION = 1; @@ -54,8 +54,8 @@ public class DatabaseFile { try { String string = obj.toString(4); - return string.getBytes("UTF-8"); - } catch (JSONException | UnsupportedEncodingException e) { + return string.getBytes(StandardCharsets.UTF_8); + } catch (JSONException e) { throw new RuntimeException(e); } } @@ -79,9 +79,9 @@ public class DatabaseFile { public static DatabaseFile fromBytes(byte[] data) throws DatabaseFileException { try { - JSONObject obj = new JSONObject(new String(data, "UTF-8")); + JSONObject obj = new JSONObject(new String(data, StandardCharsets.UTF_8)); return DatabaseFile.fromJson(obj); - } catch (UnsupportedEncodingException | JSONException e) { + } catch (JSONException e) { throw new DatabaseFileException(e); } } @@ -94,8 +94,8 @@ public class DatabaseFile { try { byte[] bytes = Base64.decode((String) _content); CryptResult result = creds.decrypt(bytes, _header.getParams()); - return new JSONObject(new String(result.getData(), "UTF-8")); - } catch (MasterKeyException | JSONException | UnsupportedEncodingException | Base64Exception e) { + return new JSONObject(new String(result.getData(), StandardCharsets.UTF_8)); + } catch (MasterKeyException | JSONException | Base64Exception e) { throw new DatabaseFileException(e); } } @@ -108,12 +108,12 @@ public class DatabaseFile { public void setContent(JSONObject obj, DatabaseFileCredentials creds) throws DatabaseFileException { try { String string = obj.toString(4); - byte[] dbBytes = string.getBytes("UTF-8"); + byte[] dbBytes = string.getBytes(StandardCharsets.UTF_8); CryptResult result = creds.encrypt(dbBytes); _content = Base64.encode(result.getData()); _header = new Header(creds.getSlots(), result.getParams()); - } catch (MasterKeyException | UnsupportedEncodingException | JSONException e) { + } catch (MasterKeyException | JSONException e) { throw new DatabaseFileException(e); } } diff --git a/app/src/main/java/com/beemdevelopment/aegis/encoding/Base64.java b/app/src/main/java/com/beemdevelopment/aegis/encoding/Base64.java index 61d5bcd4..09966972 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/encoding/Base64.java +++ b/app/src/main/java/com/beemdevelopment/aegis/encoding/Base64.java @@ -1,6 +1,6 @@ package com.beemdevelopment.aegis.encoding; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; public class Base64 { private static final int _flags = android.util.Base64.NO_WRAP; @@ -19,11 +19,6 @@ public class Base64 { public static String encode(byte[] data) { byte[] encoded = android.util.Base64.encode(data, _flags); - - try { - return new String(encoded, "UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } + return new String(encoded, StandardCharsets.UTF_8); } } diff --git a/app/src/main/java/com/beemdevelopment/aegis/importers/AndOtpFileImporter.java b/app/src/main/java/com/beemdevelopment/aegis/importers/AndOtpFileImporter.java index e7e36afc..16f4afeb 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/importers/AndOtpFileImporter.java +++ b/app/src/main/java/com/beemdevelopment/aegis/importers/AndOtpFileImporter.java @@ -6,7 +6,7 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -29,11 +29,9 @@ public class AndOtpFileImporter extends DatabaseFileImporter { @Override public void parse() throws DatabaseImporterException { try { - _obj = new JSONArray(new String(_stream.getBytes(), "UTF-8")); + _obj = new JSONArray(new String(_stream.getBytes(), StandardCharsets.UTF_8)); } catch (JSONException e) { throw new DatabaseImporterException(e); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); } }