本文整理汇总了VB.NET中System.Security.Cryptography.RC2CryptoServiceProvider.UseSalt属性的典型用法代码示例。如果您正苦于以下问题:VB.NET RC2CryptoServiceProvider.UseSalt属性的具体用法?VB.NET RC2CryptoServiceProvider.UseSalt怎么用?VB.NET RC2CryptoServiceProvider.UseSalt使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Security.Cryptography.RC2CryptoServiceProvider
的用法示例。
在下文中一共展示了RC2CryptoServiceProvider.UseSalt属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: MyMainModule
' 导入命名空间
Imports System.IO
Imports System.Text
Imports System.Security.Cryptography
Module MyMainModule
Sub Main()
Dim originalBytes As Byte() = ASCIIEncoding.ASCII.GetBytes("Here is some data.")
'Create a new RC2CryptoServiceProvider.
Dim rc2CSP As New RC2CryptoServiceProvider()
rc2CSP.UseSalt = True
rc2CSP.GenerateKey()
rc2CSP.GenerateIV()
'Encrypt the data.
Dim msEncrypt As New MemoryStream()
Dim csEncrypt As New CryptoStream(msEncrypt, rc2CSP.CreateEncryptor(rc2CSP.Key, rc2CSP.IV), CryptoStreamMode.Write)
'Write all data to the crypto stream and flush it.
csEncrypt.Write(originalBytes, 0, originalBytes.Length)
csEncrypt.FlushFinalBlock()
'Get encrypted array of bytes.
Dim encryptedBytes As Byte() = msEncrypt.ToArray()
'Decrypt the previously encrypted message.
Dim msDecrypt As New MemoryStream(encryptedBytes)
Dim csDecrypt As New CryptoStream(msDecrypt, rc2CSP.CreateDecryptor(rc2CSP.Key, rc2CSP.IV), CryptoStreamMode.Read)
Dim unencryptedBytes(originalBytes.Length - 1) As Byte
'Read the data out of the crypto stream.
csDecrypt.Read(unencryptedBytes, 0, unencryptedBytes.Length)
'Convert the byte array back into a string.
Dim plaintext As String = ASCIIEncoding.ASCII.GetString(unencryptedBytes)
'Display the results.
Console.WriteLine("Unencrypted text: {0}", plaintext)
Console.ReadLine()
End Sub
End Module