471,310 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,310 software developers and data experts.

Encryption Question

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.

Jan 4 '06 #1
2 1075
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

Jan 4 '06 #2
Hi,

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

--
HTH,
Rakesh Rajan
MVP, MCSD
http://www.rakeshrajan.com/
"INeedADip" wrote:
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

Jan 5 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Harold Crump | last post: by
34 posts views Thread by Blake T. Garretson | last post: by
14 posts views Thread by Ray Cassick \(Home\) | last post: by
3 posts views Thread by dmalhotr2001 | last post: by
1 post views Thread by =?Utf-8?B?bWljcm9ob2Y=?= | last post: by
25 posts views Thread by eggie5 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.