有没有办法用苹果 CryptoKit (AES.GCM) 加密一个对内存来说太大的文件?
我有一个大文件的 URL。该文件可能对内存来说太大了,因此我想使用 AES.GCM 使用此 SHA 示例中的流加密并最终解密该文件:
var hasher = SHA256()
let path = Bundle.main.path(forResource: "video", ofType: "mp4")!
let stream = InputStream(fileAtPath: path)!stream.open()
let bufferSize = 512
let buffer = UnsafeMutablePointer<UInt8>
.allocate(capacity: bufferSize)
while stream.hasBytesAvailable {
let read = stream.read(buffer, maxLength: bufferSize)
let bufferPointer = UnsafeRawBufferPointer(start: buffer,
count: read)
hasher.update(bufferPointer: bufferPointer)
}
let digest = hasher.finalize()
print(digest)
目前甚至可能吗?