xenoterracide
08/22/2019, 8:25 PM908D C60A
note: I don’t mean generate a salt I mean literally these bytes, I’m trying to test my algorithm and see if I get the same base64 encoded stringShawn
08/22/2019, 8:34 PMByte
is signed by default in Kotlin, so 0x90
is out of range - you could use the experimental unsigned types but that might open up a different can of wormsubyteArrayOf(0x90u, 0x8Du, 0xC6u, 0x0Au)
xenoterracide
08/22/2019, 8:41 PMMarko Mitic
08/22/2019, 8:42 PMShawn
08/22/2019, 8:43 PMMarko Mitic
08/22/2019, 8:43 PMShawn
08/22/2019, 8:43 PMbyteArrayOf(0x90)
, since that’s a compile error.toByte()
on each int I guess 😬xenoterracide
08/22/2019, 8:46 PMConcatenate that with the UTF-8 representation of the password (in this case):test12
908D C60A 7465 7374 3132
test12
Shawn
08/22/2019, 8:48 PMMarko Mitic
08/22/2019, 8:50 PMxenoterracide
08/22/2019, 8:56 PMubyteArrayOf
new in 1.3? if so… I’m still using 1.2Marko Mitic
08/22/2019, 9:01 PMxenoterracide
08/22/2019, 9:01 PMMarko Mitic
08/22/2019, 9:04 PMimport kotlin.random.Random
import kotlin.text.Charsets.UTF_8
fun a(pass: String, seed: Long): String {
val random = Random(seed)
val salt: ByteArray = random.nextBytes(4)
val passBytes = pass.toByteArray(charset = UTF_8)
val toHash = salt + passBytes
val hashed = sha256(toHash)
return toBase64(salt + hashed)
}
fun sha256(toHash: ByteArray): ByteArray {
TODO("not implemented")
}
fun toBase64(bytes: ByteArray): String {
TODO("not implemented")
}
xenoterracide
08/22/2019, 9:06 PM