diff --git a/core/security/src/main/java/org/sopt/official/security/CryptoManagerImpl.kt b/core/security/src/main/java/org/sopt/official/security/CryptoManagerImpl.kt index 41f685ed..2be279ea 100644 --- a/core/security/src/main/java/org/sopt/official/security/CryptoManagerImpl.kt +++ b/core/security/src/main/java/org/sopt/official/security/CryptoManagerImpl.kt @@ -32,15 +32,9 @@ import javax.crypto.Cipher import javax.crypto.KeyGenerator import javax.crypto.SecretKey import javax.crypto.spec.GCMParameterSpec +import javax.inject.Inject -object CryptoManagerImpl : CryptoManager { - private const val KEY_STORE_TYPE = "AndroidKeyStore" - private const val KEY_ALGORITHM = KeyProperties.KEY_ALGORITHM_AES - private const val BLOCK_MODE = KeyProperties.BLOCK_MODE_GCM - private const val PADDING = "NoPadding" - private const val TRANSFORMATION = "$KEY_ALGORITHM/$BLOCK_MODE/$PADDING" - private const val T_LEN = 128 - +class CryptoManagerImpl @Inject constructor() : CryptoManager { private val keyStore = KeyStore.getInstance(KEY_STORE_TYPE).apply { load(null) } private val keyGenerator by lazy { KeyGenerator.getInstance(KEY_ALGORITHM, KEY_STORE_TYPE) } @@ -83,4 +77,13 @@ object CryptoManagerImpl : CryptoManager { encryptedContent.data ) } + + companion object { + private const val KEY_STORE_TYPE = "AndroidKeyStore" + private const val KEY_ALGORITHM = KeyProperties.KEY_ALGORITHM_AES + private const val BLOCK_MODE = KeyProperties.BLOCK_MODE_GCM + private const val PADDING = "NoPadding" + private const val TRANSFORMATION = "$KEY_ALGORITHM/$BLOCK_MODE/$PADDING" + private const val T_LEN = 128 + } } diff --git a/core/security/src/main/java/org/sopt/official/security/di/SecurityModule.kt b/core/security/src/main/java/org/sopt/official/security/di/SecurityModule.kt new file mode 100644 index 00000000..3c3c471b --- /dev/null +++ b/core/security/src/main/java/org/sopt/official/security/di/SecurityModule.kt @@ -0,0 +1,41 @@ +/* +* MIT License +* Copyright 2024 SOPT - Shout Our Passion Together +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* https://www.apache.org/licenses/LICENSE-2.0 +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ +package org.sopt.official.security.di + +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import org.sopt.official.security.CryptoManager +import org.sopt.official.security.CryptoManagerImpl +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +abstract class SecurityModule { + @Singleton + @Binds + abstract fun bindsCryptoManager(cryptoManagerImpl: CryptoManagerImpl): CryptoManager +} \ No newline at end of file