]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/manager/storage/SignalAccount.java
Replace Base64 class from libsignal with java.util.Base64
[signal-cli] / src / main / java / org / asamk / signal / manager / storage / SignalAccount.java
index 9721ebea10a053745ac22a7da06e3e0cb9892c09..9922ca57d05f0f3e54d91d77af1ae38281038b7e 100644 (file)
@@ -41,7 +41,6 @@ import org.whispersystems.libsignal.util.Pair;
 import org.whispersystems.signalservice.api.crypto.UnidentifiedAccess;
 import org.whispersystems.signalservice.api.kbs.MasterKey;
 import org.whispersystems.signalservice.api.push.SignalServiceAddress;
-import org.whispersystems.util.Base64;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -53,6 +52,7 @@ import java.nio.channels.Channels;
 import java.nio.channels.ClosedChannelException;
 import java.nio.channels.FileChannel;
 import java.nio.channels.FileLock;
+import java.util.Base64;
 import java.util.Collection;
 import java.util.UUID;
 import java.util.stream.Collectors;
@@ -200,8 +200,8 @@ public class SignalAccount implements Closeable {
             }
             final ProfileKey profileKey;
             try {
-                profileKey = new ProfileKey(Base64.decode(profileKeyString));
-            } catch (InvalidInputException | IOException e) {
+                profileKey = new ProfileKey(Base64.getDecoder().decode(profileKeyString));
+            } catch (InvalidInputException ignored) {
                 continue;
             }
             contact.profileKey = null;
@@ -264,7 +264,7 @@ public class SignalAccount implements Closeable {
         JsonNode pinMasterKeyNode = rootNode.get("pinMasterKey");
         pinMasterKey = pinMasterKeyNode == null || pinMasterKeyNode.isNull()
                 ? null
-                : new MasterKey(Base64.decode(pinMasterKeyNode.asText()));
+                : new MasterKey(Base64.getDecoder().decode(pinMasterKeyNode.asText()));
         if (rootNode.has("signalingKey")) {
             signalingKey = Utils.getNotNullNode(rootNode, "signalingKey").asText();
         }
@@ -280,7 +280,8 @@ public class SignalAccount implements Closeable {
         }
         if (rootNode.has("profileKey")) {
             try {
-                profileKey = new ProfileKey(Base64.decode(Utils.getNotNullNode(rootNode, "profileKey").asText()));
+                profileKey = new ProfileKey(Base64.getDecoder()
+                        .decode(Utils.getNotNullNode(rootNode, "profileKey").asText()));
             } catch (InvalidInputException e) {
                 throw new IOException(
                         "Config file contains an invalid profileKey, needs to be base64 encoded array of 32 bytes",
@@ -395,11 +396,12 @@ public class SignalAccount implements Closeable {
                 .put("isMultiDevice", isMultiDevice)
                 .put("password", password)
                 .put("registrationLockPin", registrationLockPin)
-                .put("pinMasterKey", pinMasterKey == null ? null : Base64.encodeBytes(pinMasterKey.serialize()))
+                .put("pinMasterKey",
+                        pinMasterKey == null ? null : Base64.getEncoder().encodeToString(pinMasterKey.serialize()))
                 .put("signalingKey", signalingKey)
                 .put("preKeyIdOffset", preKeyIdOffset)
                 .put("nextSignedPreKeyId", nextSignedPreKeyId)
-                .put("profileKey", Base64.encodeBytes(profileKey.serialize()))
+                .put("profileKey", Base64.getEncoder().encodeToString(profileKey.serialize()))
                 .put("registered", registered)
                 .putPOJO("axolotlStore", signalProtocolStore)
                 .putPOJO("groupStore", groupStore)