adds integer parse for fernet iteration

This commit is contained in:
Raphael Maenle 2021-12-14 22:02:19 +01:00
parent 8c16ff344e
commit 3d42f0ca2e

View File

@ -11,6 +11,7 @@ import com.macasaet.fernet.Token
import com.macasaet.fernet.StringValidator import com.macasaet.fernet.StringValidator
import com.macasaet.fernet.Validator import com.macasaet.fernet.Validator
import com.maenle.bump.MainActivity import com.maenle.bump.MainActivity
import java.math.BigInteger
import java.time.Duration import java.time.Duration
import java.time.temporal.TemporalAmount import java.time.temporal.TemporalAmount
@ -34,11 +35,11 @@ class MessageProcessor {
// Data from encryption // Data from encryption
val decoded : ByteArray = Base64.getUrlDecoder().decode(message) val decoded : ByteArray = Base64.getUrlDecoder().decode(message)
val salt = decoded.copyOfRange(0, 16) val salt = decoded.copyOfRange(0, 16)
val iter = decoded.copyOfRange(16, 20) val iter : Int = BigInteger(decoded.copyOfRange(16, 20)).toInt()
val str_token = String(Base64.getUrlEncoder().encode(decoded.copyOfRange(20, decoded.size))) val str_token = String(Base64.getUrlEncoder().encode(decoded.copyOfRange(20, decoded.size)))
// Derive Fernet key // Derive Fernet key
val saltedKey = deriveKey(key, salt, 100_000) val saltedKey = deriveKey(key, salt, iter)
val fernetKey = Key(saltedKey) val fernetKey = Key(saltedKey)
val token = val token =