forked from dotnet/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.vb
45 lines (29 loc) · 1.57 KB
/
example.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'<SNIPPET1>
Imports System.Security.Cryptography
Module SCSign
Sub Main(ByVal args() As String)
' To idendify the Smart Card CryptoGraphic Providers on your
' computer, use the Microsoft Registry Editor (Regedit.exe).
' The available Smart Card CryptoGraphic Providers are listed
' in HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\Defaults\Provider.
' Create a new CspParameters object that identifies a
' Smart Card CryptoGraphic Provider.
' The 1st parameter comes from HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\Defaults\Provider Types.
' The 2nd parameter comes from HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\Defaults\Provider.
Dim csp As New CspParameters(1, "Schlumberger Cryptographic Service Provider")
csp.Flags = CspProviderFlags.UseDefaultKeyContainer
' Initialize an RSACryptoServiceProvider object using
' the CspParameters object.
Dim rsa As New RSACryptoServiceProvider(csp)
' Create some data to sign.
Dim data() As Byte = {0, 1, 2, 3, 4, 5, 6, 7}
Console.WriteLine("Data : " + BitConverter.ToString(data))
' Sign the data using the Smart Card CryptoGraphic Provider.
Dim sig As Byte() = rsa.SignData(data, "SHA1")
Console.WriteLine("Signature : " + BitConverter.ToString(sig))
' Verify the data using the Smart Card CryptoGraphic Provider.
Dim verified As Boolean = rsa.VerifyData(data, "SHA1", sig)
Console.WriteLine("Verified")
End Sub
End Module
'</SNIPPET1>