Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Proto Datastoreを使う前の心構え

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for bigbackboom bigbackboom
November 11, 2024
270

Proto Datastoreを使う前の心構え

Avatar for bigbackboom

bigbackboom

November 11, 2024
Tweet

Transcript

  1. Jetpack Datastore • 共通の利点 ◦ DBと比べて導入が簡単 ◦ 両者裏でProtocol Bufferを利用しているので高速 •

    共通の弱点 ◦ データは部分更新できないため複雑なデータは効率が悪い ◦ Protocol Buffer自体がマイナー
  2. 結論 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の作成部分
  3. 結論 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の作成部分 • KEY_SETの名前系の設 定を端折ると、アプリを 立ち上げ直すたびに複合 が不可能になる。