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. 5 2593
"Cor" <no*@non.com> wrote in message
news:Oy**************@TK2MSFTNGP09.phx.gbl... Hi Sia Jai Sung
Have a look at the text.encoder class
http://msdn.microsoft.com/library/de...classtopic.asp
Just to follow up.
The Convert2ByteArray function you posted did a manual ASCII encoding of the
string.
Just replace it with
dim b() as byte = System.Text.Encoding.Unicode.GetBytes(s)
David
The problem is the Convert2ByteArray function, which is a manual way of
doing what can be done with .NET classes. For example, for Unicode byte
arrays, you can use:
Dim MyByteArray As byte() =
System.Text.Encoding.Unicode.GetBytes(InputString)
The Convert2ByteArray function is essentially the same as:
Dim MyByteArray As byte() = System.Text.Encoding.ASCII.GetBytes(InputString)
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
************************************************** ********************
Think Outside the Box!
************************************************** ********************
"Sia Jai Sung" <@thunder@stormex@yahoo@com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl... 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.
Thanks for the help, I change the encrypt function to this,
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 = System.Text.Encoding.Unicode.GetBytes(strInput)
objDES = New DESCryptoServiceProvider()
objEncryptor = objDES.CreateEncryptor( arrDESKey, arrDESIV )
arrResult = objEncryptor.TransformFinalBlock (arrInput, 0,
arrInput.Length())
strOutput = Convert.ToBase64String (arrResult)
EncryptString = 1
End Function
now it can accept anything even chinese character, but for decryption
function,
how do I convert an array of byte back to string?
"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamM> wrote in
message news:Ou**************@TK2MSFTNGP12.phx.gbl... The problem is the Convert2ByteArray function, which is a manual way of doing what can be done with .NET classes. For example, for Unicode byte arrays, you can use:
Dim MyByteArray As byte() = System.Text.Encoding.Unicode.GetBytes(InputString)
The Convert2ByteArray function is essentially the same as:
Dim MyByteArray As byte() =
System.Text.Encoding.ASCII.GetBytes(InputString) -- Gregory A. Beamer MVP; MCP: +I, SE, SD, DBA
************************************************** ******************** Think Outside the Box! ************************************************** ******************** "Sia Jai Sung" <@thunder@stormex@yahoo@com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl... 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.
Here is my decrypt dunction , looks like its working, Thanks for all the
help offerd.
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())
Dim uniDecoder As Decoder = Encoding.Unicode.GetDecoder()
Dim charCount As Integer = uniDecoder.GetCharCount(arrResult, 0,
arrResult.Length)
Dim chars() As Char, i as Integer
chars = New Char(charCount - 1) {}
Dim charsDecodedCount As Integer = uniDecoder.GetChars(arrResult,
0, arrResult.Length, chars, 0)
for i = 0 to chars.Length()-1
strOutput &= chars(i)
next
DecryptString = 1
End Function
"Sia Jai Sung" <@thunder@stormex@yahoo@com> wrote in message
news:u1*************@TK2MSFTNGP11.phx.gbl... Thanks for the help, I change the encrypt function to this,
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 = System.Text.Encoding.Unicode.GetBytes(strInput) objDES = New DESCryptoServiceProvider() objEncryptor = objDES.CreateEncryptor( arrDESKey, arrDESIV ) arrResult = objEncryptor.TransformFinalBlock (arrInput, 0, arrInput.Length()) strOutput = Convert.ToBase64String (arrResult) EncryptString = 1 End Function
now it can accept anything even chinese character, but for decryption function, how do I convert an array of byte back to string?
"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamM> wrote in message news:Ou**************@TK2MSFTNGP12.phx.gbl... The problem is the Convert2ByteArray function, which is a manual way of doing what can be done with .NET classes. For example, for Unicode byte arrays, you can use:
Dim MyByteArray As byte() = System.Text.Encoding.Unicode.GetBytes(InputString)
The Convert2ByteArray function is essentially the same as:
Dim MyByteArray As byte() = System.Text.Encoding.ASCII.GetBytes(InputString) -- Gregory A. Beamer MVP; MCP: +I, SE, SD, DBA
************************************************** ******************** Think Outside the Box! ************************************************** ******************** "Sia Jai Sung" <@thunder@stormex@yahoo@com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl... 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.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Alan Murrell |
last post by:
Hello,
I am setting up a Postfix + MySQL + Courier-IMAP system. I am trying
to write a shell script which will insert the values into the
database. For the password encryption, I wish to use...
|
by: Mark Hanford |
last post by:
I've been setting up a new MySQL/PHP site which will contain store
some CC details, and have been wondering how to pass the keys.
CC's are written in a similar way to:
INSERT INTO cc (ccName,...
|
by: underwmd |
last post by:
Hello,
My problem is two fold.
1) I must support a deployed legacy application written in VB6 SP5. I
need to export data from a database, compress it and the encrypt the data
using 3DES (to...
|
by: Tommy |
last post by:
I want to encrypt the values of my cookies. I found out that I could
create a FormsAuthenticationTicket, and use the
FormsAuthentication.Encrypt method to encrypt the cookie.
However, I do not...
|
by: jayender.vs |
last post by:
Well .. i have a text box .. and in that i will enter a letter say"A"
and in return there should be a message box saying the encrypted value
say "J".
In simple :
how to encrypt a letter in...
|
by: Max Vit |
last post by:
Here is my problem: I have an application built in Access that outputs
sensitive data to a text file.
I would like to encrypt this data *whilst* the file is being
outputted.
The encryption I was...
|
by: Aneesh P |
last post by:
Hi All,
I need to encrypt some fields esp password key values in configuration
file while installting the application using .Net installer project
and decrypt those values from my...
|
by: cmk128 |
last post by:
Hi
I need to put my php source to customer's server and i don't want
it to view the code because i am getting his monthly fee. How can i
encrypt it? Any free tool? I am a newbiesssss
thanks
from...
|
by: rockdale |
last post by:
I followed this article,
http://msdn2.microsoft.com/en-us/library/zhhddkxy.aspx
My command is:
aspnet_regiis -pe "connectionStrings" -app "/myWebSiteName" -site
711831 -prov...
|
by: Gilles Ganault |
last post by:
Hello
I'd like to encrypt a customer's organization name to use this as
their password to launch our application, and decrypt it within our
VB5 application.
We will then use this information...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |