我正在使用加密 swift 库但是我必须在 swift 中编写以下逻辑,因为我在 kotlin 中非常新来理解语法。
任何线索将不胜感激
fun decryptAES(data: ByteArray, secretKey: ByteArray): ByteArray {
try {
val byteBuffer = ByteBuffer.wrap(data)
val ivLength = byteBuffer.int
if (ivLength < 12 || ivLength >= 16) {
throw IllegalArgumentException("invalid iv length")
}
val iv = ByteArray(ivLength)
byteBuffer.get(iv)
val cipherText = ByteArray(byteBuffer.remaining())
byteBuffer.get(cipherText)
val encryptCipher = Cipher.getInstance("AES/GCM/PKCS5Padding")
encryptCipher.init(Cipher.DECRYPT_MODE, SecretKeySpec(secretKey, "AES"), GCMParameterSpec(128, iv))
return encryptCipher.doFinal(cipherText)
} finally {
Arrays.fill(secretKey, 0.toByte())
}
}