Skip to content

Commit

Permalink
app: Follow up cryptography 0.4.0 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
YuKongA committed Oct 15, 2024
1 parent d10d550 commit b0a180e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions composeApp/src/commonMain/kotlin/Crypto.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import dev.whyoleg.cryptography.CryptographyProvider
import dev.whyoleg.cryptography.DelicateCryptographyApi
import dev.whyoleg.cryptography.algorithms.symmetric.AES
import dev.whyoleg.cryptography.algorithms.AES
import kotlin.io.encoding.Base64
import kotlin.io.encoding.ExperimentalEncodingApi

Expand All @@ -13,10 +13,10 @@ expect fun generateKey()
/**
* Generate a Cipher to be used by the xiaomi server.
*/
suspend fun miuiCipher(securityKey: ByteArray): AES.CBC.Cipher {
suspend fun miuiCipher(securityKey: ByteArray): AES.IvCipher {
val provider = provider()
val aesCBC = provider.get(AES.CBC) // AES CBC
val key = aesCBC.keyDecoder().decodeFrom(AES.Key.Format.RAW, securityKey)
val key = aesCBC.keyDecoder().decodeFromByteArray(AES.Key.Format.RAW, securityKey)
return key.cipher(true) // PKCS5Padding
}

Expand All @@ -28,10 +28,10 @@ suspend fun miuiCipher(securityKey: ByteArray): AES.CBC.Cipher {
*
* @return Encrypted JSON text
*/
@OptIn(DelicateCryptographyApi::class, ExperimentalEncodingApi::class)
@OptIn(ExperimentalEncodingApi::class, DelicateCryptographyApi::class)
suspend fun miuiEncrypt(jsonRequest: String, securityKey: ByteArray): String {
val cipher = miuiCipher(securityKey)
val encrypted = cipher.encrypt(iv, jsonRequest.encodeToByteArray())
val encrypted = cipher.encryptWithIv(iv, jsonRequest.encodeToByteArray())
return Base64.UrlSafe.encode(encrypted)
}

Expand All @@ -47,7 +47,7 @@ suspend fun miuiEncrypt(jsonRequest: String, securityKey: ByteArray): String {
suspend fun miuiDecrypt(encryptedText: String, securityKey: ByteArray): String {
val cipher = miuiCipher(securityKey)
val encryptedTextBytes = Base64.Mime.decode(encryptedText)
val decryptedTextBytes = cipher.decrypt(iv, encryptedTextBytes)
val decryptedTextBytes = cipher.decryptWithIv(iv, encryptedTextBytes)
return decryptedTextBytes.decodeToString()
}

Expand Down
2 changes: 1 addition & 1 deletion composeApp/src/commonMain/kotlin/misc/AppUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import data.DataHelper
import data.DeviceInfoHelper
import data.RomInfoHelper
import dev.whyoleg.cryptography.DelicateCryptographyApi
import dev.whyoleg.cryptography.algorithms.digest.MD5
import dev.whyoleg.cryptography.algorithms.MD5
import getRecoveryRomInfo
import iconLink
import isWeb
Expand Down

0 comments on commit b0a180e

Please sign in to comment.