Mega Code Archive

 
Categories / VB.Net by API / System Security Cryptography
 

DESCryptoServiceProvider CreateEncryptor() TransformFinalBlock

Imports System.Security.Cryptography Imports System.Text.ASCIIEncoding Imports System.IO Public Class Tester     Public Shared Sub Main             'Dim str As String = "1234567890asdfgh"             'must be exactly 16 characters long             Dim sSource, sKey, sIV, sResult As String             sSource = "string"             Dim objDES As New DESCryptoServiceProvider()             Dim objStream As New MemoryStream(ASCII.GetBytes(sSource), False)             sKey = "12345678"             sIV = "12345678"             objDES.IV = ASCII.GetBytes(sIV)             objDES.Key = ASCII.GetBytes(sKey)             sResult = ASCII.GetChars(objDES.CreateEncryptor().TransformFinalBlock(ASCII.GetBytes(sSource), 0, sSource.Length))             Console.WriteLine(sResult)             'sResult = ASCII.GetChars(objDES.CreateDecryptor().TransformFinalBlock(ASCII.GetBytes(sSource), 0, sSource.Length))             'Console.WriteLine(sResult)          End Sub End Class