Go io.Reader Decrypt Example
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by reading the existing Go awskmsmrkkeyring example and the Go Decrypt API entry point. Determine how the SDK consumes a complete ciphertext stream rather than individual chunks, and use the Python streaming example and reported Incomplete message as reference. Done means a documented Go example decrypts an io.Reader under the stated commitment policy.
Written by the indexing model from the issue text.
Description
Hi there! Can there be an example of using the golang esdk to decrypt from a readable stream via an io.Reader?
I'm working on an example where the ciphertext is created with AWS Encryption SDK using a multiregion key and RequireEncryptAllowDecrypt commitment policy. Using a modified version of the awskmsmrkkeyring example, I can decrypt the entire file if I load it all into memory.
I'm not sure if the std lib way to do it is to use cipher.StreamReader? Particularly, I just don't know what to use for the nonce, key, and whether or not it is using GCM or some other block mode, or how to connect that to the esdk client
Thank you for any help!
Creating the encrypted file with this script:
import argparse
import sys
import aws_encryption_sdk as aes
def main(infile, outfile):
client = aes.EncryptionSDKClient(
commitment_policy=aes.CommitmentPolicy.REQUIRE_ENCRYPT_ALLOW_DECRYPT,
)
key_provider = aes.StrickAwsKmsMasterKeyProvider(
key_ids=[
__myKeyArn__
],
)
with client.stream(mode="e", source=infile, key_provider=key_provider) as encryptor:
for chunk in encryptor:
outfile.write(chunk)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Encrypt a file")
parser.add_argument("--input", type=argparse.FileType("rb"), help="File to encrypt", default=sys.stdin, required=False)
parser.add_argument("--output", type=argparse.FileType("wb"), help="Encrypted output file", required=True)
args = parser.parse_args()
main(args.input, args.output)
Edit: My attempt to decrypt chunk by chunk was along these lines, got a Incomplete message: ReadFramedMessageBody :
func(input io.Reader, output io.Reader) {
// For brevity not doing any error handling
buffer := make([]byte, 4096) // 4096 byte frames
var n int
var err error
for {
n, err = input.Read(buffer)
if n <= 0 {
break
}
decryptResp, err := encryptionClient.Decrypt(context.TODO(), esdktypes.DecryptInput{
Keyring: keyring, // Created using the mrk example
Ciphertext: buffer[:n]
})
// handle err
output.Write(decryptResp.Plaintext)
}
// ...
}
- Dominant language
- Rust
- Stars
- 68
- Forks
- 29
- Avg merge
- 5d 2h
- Merged PRs (30d)
- 1
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from aws/aws-encryption-sdk
-
golang
Difficulty 4/5 3-5 days Newbie friendliness 42/100
aws/aws-encryption-sdk#902 · 5 comments ·
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 35/100
aws/aws-encryption-sdk#899 ·
-
Difficulty 5/5 Over a week Newbie friendliness 15/100
aws/aws-encryption-sdk#659 · 4 reactions ·
-
Difficulty 3/5 1-2 days Newbie friendliness 42/100
aws/aws-encryption-sdk#620 · 1 comment · 4 reactions ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
aws/aws-encryption-sdk#318 ·
All issues in aws/aws-encryption-sdk
Similar issues
-
area/backends bug session-analysis
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
Maintainers usually reply within 1 day
-
docs good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
crash
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 2 days
-
Difficulty 1/5 Under an hour Newbie friendliness 65/100
aaif-goose/goose#13125 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day