-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a bug in the encrypt sample, that was causing the decrypt to fail #23816
Conversation
docs/standard/security/snippets/decrypting-data/csharp/aes-decrypt.cs
Outdated
Show resolved
Hide resolved
docs/standard/security/snippets/decrypting-data/csharp/aes-decrypt.cs
Outdated
Show resolved
Hide resolved
docs/standard/security/snippets/decrypting-data/vb/aes-decrypt.vb
Outdated
Show resolved
Hide resolved
docs/standard/security/snippets/encrypting-data/vb/aes-encrypt.vb
Outdated
Show resolved
Hide resolved
docs/standard/security/snippets/decrypting-data/csharp/aes-decrypt.cs
Outdated
Show resolved
Hide resolved
docs/standard/security/snippets/encrypting-data/csharp/aes-encrypt.cs
Outdated
Show resolved
Hide resolved
docs/standard/security/snippets/decrypting-data/csharp/aes-decrypt.cs
Outdated
Show resolved
Hide resolved
docs/standard/security/snippets/encrypting-data/csharp/aes-encrypt.cs
Outdated
Show resolved
Hide resolved
docs/standard/security/snippets/decrypting-data/csharp/aes-decrypt.cs
Outdated
Show resolved
Hide resolved
docs/standard/security/snippets/decrypting-data/csharp/aes-decrypt.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but I added a request for @bartonjs to review.
docs/standard/security/snippets/decrypting-data/csharp/aes-decrypt.cs
Outdated
Show resolved
Hide resolved
docs/standard/security/snippets/decrypting-data/csharp/aes-decrypt.cs
Outdated
Show resolved
Hide resolved
The title says that it's fixing a bug in the sample, but there are so many aesthetic changes that I can't see what may have actually needed to be changed. I strongly recommend using braced usings for cryptographic/security code (and, honestly, for all code, but less strongly). But they already weren't, so ::shrug::. I'm not sure that the target-typed new enhances readability here. (Personally, I only use it for long lines or multiple-argument generics) The calls to CreateEncryptor and CreateDecryptor produce IDisposable values that never get disposed (CryptoStream doesn't dispose them). If we're trying for perfection with our IDisposable-usings these'll get pulled out. And, finally, the snippets lifted into the concept documents no longer match what the samples have. If we want to hand wave and say that they're only highlighting the functional aspects of the code (which is why they're not showing the using statements), that's fine, but the encryption document shows a call to CreateEncryptor(key, iv) when the sample has changed to CreateEncryptor(). No major blockers, but these are my aesthetic observations. It does look like the decrypt and encrypt samples are matched pairs. |
Co-authored-by: Youssef Victor <youssefvictor00@gmail.com>
2b7c65f
to
ddeeec9
Compare
Thanks for the review, @bartonjs and @tdykstra. Yes, that was actually the bug that was being addressed here. I am following your advice now on the explicit scoping of the disposable implementations, part of the issue was not properly scoping these - careless of me really. I still need someone's approval to merge this one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks better 😄
You have done a great job ). Thank you. I was late for the party, but maybe it will come in handy. When decrypting, a single asynchronous call is used |
Summary
using
to avoid encryption errorsFixes #23814
Internal preview
✔️ Encrypting data
✔️ Decrypting data