Slide 22
Slide 22 text
結論
class AeadEncryptionHelper(context: Context) {
private val aead by lazy {
AeadConfig.register()
AndroidKeysetManager.Builder()
.withSharedPref(
context,
KEY_SET_NAME,
KEY_SET_FILE_NAME
)
.withKeyTemplate(KeyTemplates.get(
"AES256_GCM"))
.withMasterKeyUri(
KEY_SET_MASTER_URI
)
.build()
.keysetHandle
.getPrimitive(Aead::
class.java)
}
fun encrypt(plaintext: String): ByteArray {
return aead.encrypt(plaintext.
toByteArray(), null)
}
fun decrypt(encryptedText: ByteArray): String {
return String(aead.decrypt(encryptedText, null))
}
private companion object {
const val KEY_SET_NAME = "{key_set_name}"
const val KEY_SET_FILE_NAME = "{key_set_file_name}"
const val KEY_SET_MASTER_URI = " 適当な://名前"
}
}
● 作成した暗号化クラス
● ポイントは
AndroidKeySetManag
erの作成部分