Yasic
Yasic

Reputation: 77

Is there a streaming way to decrypt AES256GCM large files?

I'm currently using CryptoKit to decrypt AES256GCM encrypted files.

func decryptByCombined(_ key: String, authenticating: Data?) -> Data {
    let key = SymmetricKey(data: key.bytes())
    let sb = try! AES.GCM.SealedBox(combined: self)
    if let authenticating {
        return try! AES.GCM.open(sb, using: key, authenticating: authenticating)
    }
    return try! AES.GCM.open(sb, using: key)
}

My files can be very large, and reading them into memory all at once can easily cause OOM. I'd like to know if there is a way to stream decryption, decrypt a small portion, then read the next portion, and so on.

Upvotes: 0

Views: 38

Answers (0)

Related Questions