Base58 & KDF
Base58 Encoding
val data = "Kodium Pure Kotlin".encodeToByteArray()
// Standard Base58
val b58 = data.encodeToBase58String()
val decoded = b58.decodeBase58()
// Base58 with Checksum (Standard in Bitcoin and many crypto networks)
// The checksum helps prevent accidental typos when users manually enter or copy strings.
val b58Check = data.encodeToBase58WithChecksum()
val decodedCheck = b58Check.decodeBase58WithChecksum()Password-Based Key Derivation (PBKDF2)
val password = "UserPassword123".encodeToByteArray()
val salt = "RandomSalt".encodeToByteArray() // Should be securely random and at least 16 bytes
// Derive a 32-byte key (suitable for SecretBox)
val derivedKey = KDF.deriveKey(
password = password,
salt = salt,
iterations = 100_000, // Higher iterations = slower derivation, harder to brute force
keyLengthBytes = 32
)Last updated