473,396 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 1106
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Harold Crump | last post by:
Greetings, I have a requirement of storing some .xml files on a web server. The files will contain financial information like credit card numbers, so I would like to encrypt them. The files...
34
by: Blake T. Garretson | last post by:
I want to save some sensitive data (passwords, PIN numbers, etc.) to disk in a secure manner in one of my programs. What is the easiest/best way to accomplish strong file encryption in Python? ...
14
by: Ray Cassick \(Home\) | last post by:
Ok, time to ask the question here.. I have been battling over this one for sometime now and just have to ask it. I have created a few classes that I use to act a security keys. These classes get...
4
by: panik | last post by:
Hi, I'm looking for something similar to Encryption. I'd like to generate URL's with a format that avoids visible ID's (e.g. http://thesite/viewlink.aspx?ID=105) Instead, I'd like to generate a...
113
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same...
1
by: David | last post by:
One thing that's always puzzled me about implementing encryption on remote asp.net apps is where to store the keys. The demo code indicate that you include them in a configuration file, but this...
3
by: dmalhotr2001 | last post by:
I was wondering whether anyone ever dealt with encryption that are visa compliant with credit card numbers: On 3.4 of this document...
1
by: =?Utf-8?B?bWljcm9ob2Y=?= | last post by:
Short version: Is there a way to configure (preferably programmatically) the max encryption strength that will be used by the framework when connecting to a particular SSL-protected web service? ...
25
by: eggie5 | last post by:
I have a form where a user can change his password, but I'm confused on how to prevent this from being transmitted in plain text. Well, I know how not to transmit it in plain text - use any type...
19
by: klenwell | last post by:
Another request for comments here. I'd like to accomplish something like the scheme outlined at this page here: http://tinyurl.com/3dtcdr In a nutshell, the form uses javascript to hash...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
Oralloy
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.