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.