Hi,
I have a class that I modify from a sample program, like below
==========================================
Imports System
Imports System.Web.UI
Imports System.Security.Cryptography
public Class CSoccerichCommonFunc
private DESKey as String = "ABCDEFGH"
private DESIV as String = "HRHDDKGF"
private Function Convert2ByteArray( strInput As String ) As Byte()
Dim intCounter As Integer
Dim arrChar As Char()
arrChar = strInput.ToCharArray()
Dim arrByte( arrChar.Length - 1 ) As Byte
For intCounter = 0 To arrByte.Length - 1
arrByte( intCounter ) = Convert.ToByte( arrChar( intCounter ) )
Next
Return arrByte
End Function
Function EncryptString (strInput as String, byref strOutput as String) as
Integer
EncryptString = 0
Dim arrDesKey As Byte()
Dim arrDesIV As Byte()
Dim arrInput As Byte()
Dim arrResult As Byte()
Dim objDes as DESCryptoServiceProvider
Dim objEncryptor As ICryptoTransform
arrDESKey = Convert2ByteArray(DESKey)
arrDESIV = Convert2ByteArray (DESIV)
arrInput = Convert2ByteArray (strInput)
objDES = New DESCryptoServiceProvider()
objEncryptor = objDES.CreateEncryptor( arrDESKey, arrDESIV )
arrResult = objEncryptor.TransformFinalBlock (arrInput, 0,
arrInput.Length())
strOutput = Convert.ToBase64String (arrResult)
EncryptString = 1
End Function
End Class
==========================================
here is my questions
a) The encryption will work only when user imput string that are all ASCII
character, if they input eg. Chinese character it will fail.
How to solve that ?
b) How to do a decyption ?
I try like this,
Function DecryptString (strInput as String, byref strOutput as String) as
Integer
DecryptString = 0
Dim arrDESKey As Byte()
Dim arrDESIV As Byte()
Dim arrResult As Byte()
Dim arrInput As Byte()
Dim objDES As DESCryptoServiceProvider
Dim objDecryptor As ICryptoTransform
arrDESKey = Convert2ByteArray( DESKey )
arrDESIV = Convert2ByteArray( DESIV )
arrInput = convert.FromBase64String(strInput)
objDES = New DESCryptoServiceProvider
objDecryptor = objDES.CreateDecryptor( arrDESKey, arrDESIV )
arrResult = objDecryptor.TransformFinalBlock (arrInput, 0,
arrInput.Length())
DecryptString = 1
End Function
but I don't know how to change array of byte back to string.
Please help, Thanks in advance for any help offered.