Simple Encryption of text string

  • Thread starter Thread starter larry mckay
  • Start date Start date
L

larry mckay

Hi,
Does anyone have any simple text string encryption routines that are
easy to implement? I'm trying to prevent users and system
administrators from figuring out how I implement things.
thanks
 
try exclusive oring each byte of a string with a value e.g.7
to decrypt repeat the procedure
this is very simple and not dificult to break, but might do what you wan

hth guy
 
I havent tested it but something like this..

dim start as string="Beginning
dim finish as string="
dim i as intege
dim mask as integer= 78 ' or whateve
for i = 1 to len(start
finish = finish & chrw(ascw(mid(start,i,1)) xor mask
next

to decrypt just do the same thing on finish and you will get start bac

hth gu

----- larry mckay wrote: ----


HOW do you do it? Do you have the code that will do it


*** Sent via Developersdex http://www.developersdex.com **
Don't just participate in USENET...get rewarded for it
 
First of all, and sorry Guy, I don't mean to pick on ya, I know you're
trying to help :-) but if data is worth encrypting, NEVER, EVER use
encoding and don't make up your own encryption schemes. There's a HUGE
security difference between encoding (simple shifting of text data in
predictable ways) and standard encryption.

Luckily, the .NET framework has a bunch of encryption stuff built in that
you can use.
Try this code out, and post any questions you may have about it (I wrote
this in a windows form):

Function Encrypt(ByVal plainText As String, ByVal key As Byte(), ByVal iv As
Byte()) As String
Dim cipher As New RijndaelManaged
Dim encryptor As ICryptoTransform = cipher.CreateEncryptor(key, iv)
Dim data As Byte() = Encoding.Unicode.GetBytes(plainText)
Return Convert.ToBase64String(encryptor.TransformFinalBlock(data, 0,
data.Length))
End Function

Function Decrypt(ByVal encryptedText As String, ByVal key As Byte(), ByVal
iv As Byte()) As String
Dim cipher As New RijndaelManaged
Dim decryptor As ICryptoTransform = cipher.CreateDecryptor(key, iv)
Dim data As Byte() = Convert.FromBase64String(encryptedText)
Return Encoding.Unicode.GetString(decryptor.TransformFinalBlock(data, 0,
data.Length))
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim key As Byte() = {170, 56, 39, 124, 31, 136, 211, 100, 180, 51, 111,
88, 217, 92, 214, 36, 164, 188, 71, 51, 36, 187, 195, 205, 87, 167, 81, 248,
173, 7, 194, 10}
Dim iv As Byte() = {33, 162, 253, 195, 255, 140, 120, 198, 25, 99, 222,
141, 182, 152, 94, 28}

Dim plainText As String = "This is a test"
Dim encryptedText As String

encryptedText = Encrypt(plainText, key, iv)
MsgBox(encryptedText)
plainText = ""
plainText = Decrypt(encryptedText, key, iv)
MsgBox(plainText)

End Sub

Of course, you'll want to create your own key and IV values. You must use
the same key (and IV) to decrypt a value as the key (and IV) that was used
to encrypt it. Other keys will not work, and will just cause an error, or
return garbage. If you use the Rijndael encryption algorithm (like i did
here), the key should be 32 bytes in length, and the IV 16 bytes.

-Rob Teixeira [MVP]
 
Back
Top