Skip to content

Commit

Permalink
Merge pull request #2119 from ccellado/better-wallet-unlock-error
Browse files Browse the repository at this point in the history
Better wallet unlock error
  • Loading branch information
kushti committed Feb 25, 2024
2 parents 1d251d5 + aa8cf53 commit c19b7dd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package org.ergoplatform.wallet.crypto
import org.ergoplatform.sdk.wallet.settings.EncryptionSettings

import javax.crypto.spec.{GCMParameterSpec, PBEKeySpec, SecretKeySpec}
import javax.crypto.{Cipher, SecretKeyFactory}
import scala.util.Try
import javax.crypto.{AEADBadTagException, Cipher, SecretKeyFactory}
import scala.util.{Failure, Try}

object AES {

Expand Down Expand Up @@ -51,7 +51,10 @@ object AES {
val cipher = Cipher.getInstance(CipherAlgoInstance)
cipher.init(Cipher.DECRYPT_MODE, keySpec, paramsSpec)

Try(cipher.doFinal(authTag ++ ciphertext))
Try(cipher.doFinal(authTag ++ ciphertext)).recoverWith ({
case _: AEADBadTagException => Failure(new Throwable("Bad wallet password"))
case e: Throwable => Failure(e)
})
}

private def deriveEncryptionKeySpec(pass: Array[Char], salt: Array[Byte])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ final class JsonSecretStorage(val secretFile: File, encryptionSettings: Encrypti
}
}
}
. fold(Failure(_), Success(_))
.fold(Failure(_), Success(_))
.flatten
}

Expand Down

0 comments on commit c19b7dd

Please sign in to comment.