簡體   English   中英

如何使用Ruby使用GPG在S3中流式傳輸和解密大文件

[英]How to stream and decrypt large files in S3 with GPG using Ruby

我正在S3中處理非常大的文件,這些文件需要解密並保存回S3中。 我們的磁盤空間和內存有限,因此流式傳輸是我們的最佳選擇。

我正在使用ruby-gpgme寶石。

這是我到目前為止的內容:

require 'gpgme'
require 'aws-sdk'

s3_credentials = Aws::Credentials.new(AWS_ACCESS_KEY_ID, AWS_SECRET_KEY_ID)
s3_client = Aws::S3::Client.new(credentials: s3_credentials)

source_file = 'in_file.gpg'
object_key = "upload/#{source_file}"
destination = File.open('out.txt', 'w+b')

crypto = GPGME::Crypto.new
source = File.open(source_file)

s3_client.get_object(bucket: bucket, key: object_key) do |chunk|
  crypto.decrypt(chunk, password: password, output: destination)
end

# As a follow-up, I will setup the script to stream directly back out to S3
# S3.get_object > GPG.decrypt > S3.upload_part

這樣可以成功解密並寫入第一個塊,但是在處理下一個塊之前解密失敗。

我假設這是因為第一個塊未正確終止,並且.decrypt不會連續從流本身讀取數據。

關於如何將塊作為流傳遞以進行解密的任何想法?

這是您可以查看的另一種方法:

https://speakerdeck.com/julik/streaming-large-files-with-ruby

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM