Код: Выделить всё
private fun loadKey(fullAlias: String, key: SecretKey) {
val keyEntry = KeyStore.SecretKeyEntry(SecretKeySpec(key.encoded, AES_ALG))
val prot: ProtectionParameter = KeyProtection.Builder(
KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT or KeyProperties.PURPOSE_SIGN)
.setBlockModes(KeyProperties.BLOCK_MODE_GCM)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
.setDigests(KeyProperties.DIGEST_SHA256, KeyProperties.DIGEST_SHA1)
.setUserAuthenticationRequired(false)
.setRandomizedEncryptionRequired(false)
.build();
keyStore.setEntry(fullAlias, keyEntry, prot)
}
Код: Выделить всё
private const val HMAC_ALGORITHM = "HmacSHA256"
fun pibaseToken(key: Key, label: ByteString): ByteString {
// val secretKeySpec = SecretKeySpec(key.encoded, HMAC_ALGORITHM)
val mac = Mac.getInstance(HMAC_ALGORITHM)
mac.init(key)
val token = mac.doFinal(label.toByteArray())
return ByteString.copyFrom(token)
}
Подробнее здесь: https://stackoverflow.com/questions/783 ... -using-pur