📄 form1.vb
字号:
Imports System.Security.Cryptography
Imports System.Text
Public Class Form1
Private rsaprovider As RSACryptoServiceProvider
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim publicKey As String = GetRSAKeyPair("DesktopKeyUnlockerContainer")
textBoxPublicKey.Text = publicKey
End Sub
Private Function GetRSAKeyPair(ByVal containerName As String) As String
'Create a CryptoServiceProvider Parameter object
Dim cspParams As CspParameters = New CspParameters()
' Set the key container name that has the RSA key pair
cspParams.KeyContainerName = containerName
'Set the CSP Provider Type PROV_RSA_FULL
cspParams.ProviderType = 1
'Set the CSP Provider Name
cspParams.ProviderName = "Microsoft Enhanced Cryptographic Provider v1.0"
'Create a new RSA provider and pass our parameter object to the constructor
'if the specified key container does not exist, a new key-pair is created.
rsaprovider = New RSACryptoServiceProvider(cspParams)
'Indicate that we would like the new key-pair to be persisted in the key
'container we specified.
rsaprovider.PersistKeyInCsp = True
'return the PUBLIC key info.
Return rsaprovider.ToXmlString(False)
End Function
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
OpenFileDialog1.CheckFileExists = True
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
textBoxFilePath.Text = OpenFileDialog1.FileName
End If
End Sub
Private Sub textBoxFilePath_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles textBoxFilePath.TextChanged
If System.IO.File.Exists(textBoxFilePath.Text) Then
Dim cipherBase64 As String = System.IO.File.ReadAllText(textBoxFilePath.Text)
Dim cipherText() As Byte = Convert.FromBase64String(cipherBase64)
' Decrypt the file using the PRIVATE key
Dim decipheredText() As Byte = rsaprovider.Decrypt(cipherText, False)
'Display the Deciphered Message
labelResult.Text = New UnicodeEncoding().GetString(decipheredText)
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -