-
Notifications
You must be signed in to change notification settings - Fork 6k
Modernize SHA-256 samples #33254
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
Merged
Merged
Modernize SHA-256 samples #33254
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 20 additions & 42 deletions
62
samples/snippets/csharp/VS_Snippets_CLR/verifyingahash/cs/program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,32 @@ | ||
//<Snippet1> | ||
using System; | ||
using System.Linq; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
|
||
class Class1 | ||
{ | ||
static void Main() | ||
{ | ||
//This hash value is produced from "This is the original message!" | ||
//using SHA256. | ||
byte[] sentHashValue = { 185, 203, 236, 22, 3, 228, 27, 130, 87, 23, 244, 15, 87, 88, 14, 43, 37, 61, 106, 224, 81, 172, 224, 211, 104, 85, 194, 197, 194, 25, 120, 217 }; | ||
|
||
//This is the string that corresponds to the previous hash value. | ||
string messageString = "This is the original message!"; | ||
|
||
byte[] compareHashValue; | ||
|
||
//Create a new instance of the UnicodeEncoding class to | ||
//convert the string into an array of Unicode bytes. | ||
UnicodeEncoding ue = new UnicodeEncoding(); | ||
//This hash value is produced from "This is the original message!" | ||
//using SHA256. | ||
byte[] sentHashValue = Convert.FromHexString("67A1790DCA55B8803AD024EE28F616A284DF5DD7B8BA5F68B4B252A5E925AF79"); | ||
|
||
//Convert the string into an array of bytes. | ||
byte[] messageBytes = ue.GetBytes(messageString); | ||
//This is the string that corresponds to the previous hash value. | ||
string messageString = "This is the original message!"; | ||
|
||
//Create a new instance of the SHA256 class to create | ||
//the hash value. | ||
SHA256 shHash = SHA256.Create(); | ||
//Convert the string into an array of bytes. | ||
byte[] messageBytes = Encoding.UTF8.GetBytes(messageString); | ||
|
||
//Create the hash value from the array of bytes. | ||
compareHashValue = shHash.ComputeHash(messageBytes); | ||
//Create the hash value from the array of bytes. | ||
byte[] compareHashValue = SHA256.HashData(messageBytes); | ||
|
||
bool same = true; | ||
//Compare the values of the two byte arrays. | ||
bool same = sentHashValue.SequenceEqual(compareHashValue); | ||
|
||
//Compare the values of the two byte arrays. | ||
for (int x = 0; x < sentHashValue.Length; x++) | ||
{ | ||
if (sentHashValue[x] != compareHashValue[x]) | ||
{ | ||
same = false; | ||
} | ||
} | ||
//Display whether or not the hash values are the same. | ||
if (same) | ||
{ | ||
Console.WriteLine("The hash codes match."); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("The hash codes do not match."); | ||
} | ||
} | ||
//Display whether or not the hash values are the same. | ||
if (same) | ||
{ | ||
Console.WriteLine("The hash codes match."); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("The hash codes do not match."); | ||
} | ||
//</Snippet1> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 6 additions & 21 deletions
27
samples/snippets/visualbasic/VS_Snippets_CLR/verifyingahash/vb/program.vb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.