From cb41a1ed664c59da7fce0ffad59fa3c2ae9ef18b Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Sat, 13 Nov 2021 10:05:05 +0200 Subject: [PATCH] fix import of encrypted json wallet on linux --- src/main/java/com/sparrowwallet/sparrow/io/Sparrow.java | 9 ++++++--- src/main/java/com/sparrowwallet/sparrow/io/Storage.java | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Sparrow.java b/src/main/java/com/sparrowwallet/sparrow/io/Sparrow.java index ba8779fd..582136e1 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Sparrow.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Sparrow.java @@ -101,9 +101,12 @@ public class Sparrow implements WalletImport, WalletExport { java.nio.file.Files.copy(inputStream, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING); PersistenceType persistenceType = Storage.detectPersistenceType(tempFile); persistenceType = (persistenceType == null ? PersistenceType.JSON : persistenceType); - File tempTypedFile = new File(tempFile.getParentFile(), tempFile.getName() + "." + persistenceType.getExtension()); - tempFile.renameTo(tempTypedFile); - tempFile = tempTypedFile; + if(persistenceType != PersistenceType.JSON || !isEncrypted(tempFile)) { + File tempTypedFile = new File(tempFile.getParentFile(), tempFile.getName() + "." + persistenceType.getExtension()); + tempFile.renameTo(tempTypedFile); + tempFile = tempTypedFile; + } + storage = new Storage(persistenceType, tempFile); if(!isEncrypted(tempFile)) { wallet = storage.loadUnencryptedWallet().getWallet(); diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Storage.java b/src/main/java/com/sparrowwallet/sparrow/io/Storage.java index a98ca266..12c4f89e 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Storage.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Storage.java @@ -13,6 +13,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.*; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.attribute.PosixFilePermission; import java.nio.file.attribute.PosixFilePermissions; @@ -373,7 +374,7 @@ public class Storage { } public static PersistenceType detectPersistenceType(File walletFile) { - try(Reader reader = new FileReader(walletFile)) { + try(Reader reader = new FileReader(walletFile, StandardCharsets.UTF_8)) { int firstChar = reader.read(); if(firstChar == 'U' || firstChar == '{') {