Encryption Question

I

INeedADip

I was able to use the different Crypto providers to encrypt data, but
this is a little too much. The encrypted strings are too long. I
don't need this to be REAL secure.
This is what we used in VB.NET, and I would like to convert it to
C#..any help would be greatly appreciated:

'The function used to encrypt the text
Private Shared Function Encrypt(ByVal strText As String, ByVal
strEncrKey As String) As String

Dim strChar As String
Dim intF As Integer
Dim intT As Integer
Dim bArray() As Byte

Try

intF = Len(strEncrKey) 'get length of key

For intT = 1 To Len(strText)
strChar = Asc(Mid(strEncrKey, (intT Mod intF) - intF *
((intT Mod intF) = 0), 1))
Mid(strText, intT, 1) = Chr(Asc(Mid(strText, intT, 1))
Xor strChar)
Next

'convert to byte array
bArray = System.Text.Encoding.ASCII.GetBytes(strText)
Return Replace(Convert.ToBase64String(bArray), "=", "")

Catch ex As Exception
Return ex.Message
End Try

End Function

And the decrypt:

'The function used to decrypt the text
Private Shared Function Decrypt(ByVal strText As String, ByVal
sDecrKey _
As String) As String

Dim strChar As String
Dim intF As Integer
Dim intT As Integer
Dim bArray() As Byte
Dim cPad As Char = Convert.ToChar("=")

Try

intF = Len(strText)

'lets first padd it it with the approriate "="'s and
convert it from base64 to the enc text
'Do Until intT >= intF
' intT += 4
'Loop
intT = intF Mod 4
If intT <> 0 Then
intT -= 4
intT = Math.Abs(intT)
End If

strText = strText.PadRight(intF + intT, cPad)

bArray = Convert.FromBase64String(strText)
strText = System.Text.Encoding.ASCII.GetString(bArray)

intF = Len(sDecrKey) 'get length of key

For intT = 1 To Len(strText)
strChar = Asc(Mid(sDecrKey, (intT Mod intF) - intF *
((intT Mod intF) = 0), 1))
Mid(strText, intT, 1) = Chr(Asc(Mid(strText, intT, 1))
Xor strChar)
Next

Return strText.Trim

Catch ex As Exception
Return ex.Message
End Try

End Function

There are just too many Microsoft.VisualBasic calls in this for me to
figure out how to convert it. I can't figure out the equivilant in C#.

Please Help.
 
I

INeedADip

I'm really not asking someone to convert every line of code for me.
But hopefully someone can see the "one to one" type of "encryption" we
were using and could suggest something similar in C#.

Thanks
 
G

Guest

Hi,

First, why are you concerned about the length of the encrypted string? Are
you storing it in a fixed field DB column?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top