반응형
companion object {
private val alg: String = "AES/CBC/PKCS5Padding"
private val key: String by lazy {
"your key".substring(0, 16)
}
private fun setCipher (mode: Int): Cipher {
val cipher = Cipher.getInstance(alg)
cipher?.init(
mode,
SecretKeySpec(key.toByteArray(), "AES"),
IvParameterSpec(key.toByteArray())
)
return cipher!!
}
fun encrypt(text: String): String {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return Base64.getEncoder()
.encodeToString(
setCipher(Cipher.ENCRYPT_MODE).doFinal(text.toByteArray())
)
}
return ""
}
fun decrypt(encryptText : String): String {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return String(
setCipher(Cipher.ENCRYPT_MODE).doFinal(Base64.getDecoder().decode(encryptText))
)
}
return ""
}
진행중 ...
반응형
'IT 이야기 > 2022_Android 이것저것' 카테고리의 다른 글
ACTION_MEDIA_SCANNER_SCAN_FILE -> deprecated (0) | 2022.12.07 |
---|---|
느린 렌더링 (버벅거림 ) (0) | 2022.09.21 |
Android Studio SamSung RemoteTestLab 이용하기. (0) | 2022.07.21 |
Image Resize (0) | 2022.06.22 |
retrofit2 Get Header 추가. (0) | 2022.05.10 |