Skip to content

Commit 7cb362d

Browse files
authored
Fix SHA384/512 examples (#9828)
* Fix SHA384/512 examples * Add project files to make Snippet Builder happy * Made snippets actually compile
1 parent 8cdb5d2 commit 7cb362d

File tree

12 files changed

+97
-46
lines changed

12 files changed

+97
-46
lines changed

snippets/csharp/System.Security.Cryptography/SHA384/Overview/source.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ protected void Method()
1212
// <Snippet1>
1313
byte[] data = new byte[DATA_SIZE];
1414
byte[] result;
15-
SHA384 shaM = new SHA384Managed();
16-
result = shaM.ComputeHash(data);
15+
16+
using (SHA384 sha384 = SHA384.Create())
17+
{
18+
result = sha384.ComputeHash(data);
19+
}
1720
// </Snippet1>
1821
}
1922
}

snippets/csharp/System.Security.Cryptography/SHA384Managed/Overview/source.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ protected void Method()
1313
byte[] data = new byte[DATA_SIZE];
1414
byte[] result;
1515

16-
SHA384 shaM = new SHA384Managed();
17-
result = shaM.ComputeHash(data);
16+
using (SHA384 shaM = new SHA384Managed())
17+
{
18+
result = shaM.ComputeHash(data);
19+
}
1820
// </Snippet1>
1921
}
2022
}

snippets/csharp/System.Security.Cryptography/SHA512/Overview/source.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ protected void Method()
1212
// <Snippet1>
1313
byte[] data = new byte[DATA_SIZE];
1414
byte[] result;
15-
SHA512 shaM = new SHA512Managed();
16-
result = shaM.ComputeHash(data);
15+
16+
using (SHA512 sha512 = SHA512.Create())
17+
{
18+
result = sha512.ComputeHash(data);
19+
}
1720
// </Snippet1>
1821
}
1922
}

snippets/csharp/System.Security.Cryptography/SHA512Managed/Overview/source.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ protected void Method()
1313
byte[] data = new byte[DATA_SIZE];
1414
byte[] result;
1515

16-
SHA512 shaM = new SHA512Managed();
17-
result = shaM.ComputeHash(data);
16+
using (SHA512 shaM = new SHA512Managed())
17+
{
18+
result = shaM.ComputeHash(data);
19+
}
1820
// </Snippet1>
1921
}
2022
}

snippets/visualbasic/VS_Snippets_CLR_Classic/classic SHA384 Example/VB/source.vb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
Imports System.ComponentModel
33
Imports System.Security.Cryptography
44

5-
Public Class Sample
6-
Protected DATA_SIZE As Integer = 1024
7-
8-
Protected Sub Method()
5+
Public Module Sample
6+
Private DATA_SIZE As Integer = 1024
7+
8+
Public Sub Main()
99
' <Snippet1>
10-
Dim data(DATA_SIZE) As Byte
11-
Dim result() As Byte
12-
Dim shaM As New SHA384Managed()
13-
result = shaM.ComputeHash(data)
10+
Dim data(DATA_SIZE) As Byte
11+
Dim result() As Byte
12+
13+
Using sha384 As SHA384 = SHA384.Create()
14+
result = sha384.ComputeHash(data)
15+
End Using
1416
' </Snippet1>
1517
End Sub
16-
End Class
18+
End Module
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<RootNamespace>vb</RootNamespace>
6+
<TargetFramework>net6.0</TargetFramework>
7+
</PropertyGroup>
8+
9+
</Project>

snippets/visualbasic/VS_Snippets_CLR_Classic/classic SHA384Managed Example/VB/source.vb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
Imports System.ComponentModel
33
Imports System.Security.Cryptography
44

5-
Public Class Sample
6-
Protected DATA_SIZE As Integer = 1024
7-
8-
Protected Sub Method()
5+
Public Module Sample
6+
Private DATA_SIZE As Integer = 1024
7+
8+
Public Sub Main()
99
' <Snippet1>
10-
Dim data(DATA_SIZE) As Byte
11-
Dim result() As Byte
12-
13-
Dim shaM As New SHA384Managed()
14-
result = shaM.ComputeHash(data)
10+
Dim data(DATA_SIZE) As Byte
11+
Dim result() As Byte
12+
Using shaM As New SHA384Managed()
13+
result = shaM.ComputeHash(data)
14+
End Using
1515
' </Snippet1>
1616
End Sub
17-
End Class
17+
End Module
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<RootNamespace>vb</RootNamespace>
6+
<TargetFramework>net6.0</TargetFramework>
7+
</PropertyGroup>
8+
9+
</Project>

snippets/visualbasic/VS_Snippets_CLR_Classic/classic SHA512 Example/VB/source.vb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
Imports System.ComponentModel
33
Imports System.Security.Cryptography
44

5-
Public Class Sample
6-
Protected DATA_SIZE As Integer = 1024
7-
8-
Protected Sub Method()
5+
Public Module Sample
6+
Private DATA_SIZE As Integer = 1024
7+
8+
Public Sub Main()
99
' <Snippet1>
10-
Dim data(DATA_SIZE) As Byte
11-
Dim result() As Byte
12-
Dim shaM As New SHA512Managed()
13-
result = shaM.ComputeHash(data)
10+
Dim data(DATA_SIZE) As Byte
11+
Dim result() As Byte
12+
13+
Using sha512 As SHA512 = SHA512.Create()
14+
result = sha512.ComputeHash(data)
15+
End Using
1416
' </Snippet1>
1517
End Sub
16-
End Class
18+
End Module
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<RootNamespace>vb</RootNamespace>
6+
<TargetFramework>net6.0</TargetFramework>
7+
</PropertyGroup>
8+
9+
</Project>

0 commit comments

Comments
 (0)