you'll want to use AES with a seed.
a seed is just a random string of data you postpend to the string (message + seed) so the encrypted result is more random.
Main Topics
Browse All TopicsHi all
Overview
In a web app that I am developing I need to email the user a piece of info. After logging on to the system they will enter this piece of info and it will use this, as well as other bits of info from the database.
This string though needs to be encrypted. It is not for security reasons as such, just to obfuscate the actual string value. It is not a database key, an ID or anything like that. Just a simple string that we do not store but instead send to the client. (Unfortunately I am not allowed to provide any more information on this :(
Once they have logged on and entered the string, it will be decrypted and displayed on the screen. As a result, the function (or two) needs to be two way.
Requirements:
1. Encrypt a short character string consisting of characters, numbers and spaces (max leng about 5).
2. The encrypted string should be of fixed length (of about 8 characters)
3. The decryption function should take this encrypted string and convert it back exactly.
4. Must not require any kind of server side install (I have access to the server but do not trust 'unknown' components and there is no budget for it as it's not mission critical).
I've tried:
Standard ROT13 functions
these only work with characters and the length is the same as the original string - so no good
MD5 Hashing
A project I worked on years ago had a MD5 hash and unhash function (I know MD% is one way, but this one wasn't :). There are a few sites that can MD5 hash a string and unhash it - but I can't find anything like this that actually displays the code. (I have an MD5 hashing function but not one to unhash it)
Various other code snippets
I've been googling this for hours, sorting through code trying to find something suitable. But no joy.
To re-iterate. The function(s) does not need to be massively complex - just enough to obfuscate the string and return a fixed length string that can then be decrypted.
I don't have the time to do it myself or I would :) Even though I just spent hours trying to find one :(
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
JagC, sounds like you are asking for encoding instead of encryption and in that case the example given should work for you, but if you are actually looking for encryption I would recommend RC4:
http://www.4guysfromrolla.
Thanks for the replies guys.
I haven't really done much in the way of encoding/encryption. Usually on larger projects we just buy the appropriate components and I don;t usually get a say in it.
As I said, it doesn't need to be 'uncrackable' just enough to obfuscate the true value. The string on its own, even enencoded, is useless on its own. And they are only given the other info they need when it goes through our unencoding method.
So I shall try it out tomorrow. :)
When I want to encrypt/encode/obfuscate, (whatever you want to call it), a simple text string I use this little set of functions;
<%
' Function encrypts the data passed
Private Function Encrypt(ByVal string)
Dim x, i, tmp
For i = 1 To Len( string )
x = Mid( string, i, 1 )
tmp = tmp & Chr( Asc( x ) + 1 )
Next
tmp = StrReverse( tmp )
Encrypt = tmp
End Function
%>
<%
' Lets run the decrypt function
Private Function Decrypt(ByVal encryptedstring)
Dim x, i, tmp
encryptedstring = StrReverse( encryptedstring )
For i = 1 To Len( encryptedstring )
x = Mid( encryptedstring, i, 1 )
tmp = tmp & Chr( Asc( x ) - 1 )
Next
Decrypt = tmp
End Function
%>
Plain Text: This is a test string.
Encrypted: /hojsut!utfu!b!tj!tjiU
Thanks for that effx, works perfectly. Even catches errors in the Decode.
michael-mirios
Thanks for the advice although at the moment it doesn't need to be especially robust and if they do tamper with the string it doesn't really matter as it won't fit with the rest of the info they recieve.
mgfranz
Unfortunately it still keeps the same number of characters and tends to keep numbers as numbers and characters as characters.
So I have to give the points to effx.
Thanks again peeps.
Business Accounts
Answer for Membership
by: effxPosted on 2007-07-05 at 09:39:15ID: 19425361
Try :
Zabcdefghi jklmnopqrs tuvwxyz012 3456789+/"
Zabcdefghi jklmnopqrs tuvwxyz012 3456789+/"
<%
Function MyASC(OneChar)
If OneChar = "" Then MyASC = 0 Else MyASC = Asc(OneChar)
End Function
Function Base64Encode(inData)
Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXY
Dim cOut, sOut, I
For I = 1 To Len(inData) Step 3
Dim nGroup, pOut, sGroup
nGroup = &H10000 * Asc(Mid(inData, I, 1)) + &H100 * MyAsc(Mid(inData, I + 1, 1)) + MyAsc(Mid(inData, I + 2, 1))
nGroup = Oct(nGroup)
nGroup = String(8 - Len(nGroup), "0") & nGroup
pOut = Mid(Base64, CLng("&o" & Mid(nGroup, 1, 2)) + 1, 1) + Mid(Base64, CLng("&o" & Mid(nGroup, 3, 2)) + 1, 1) + Mid(Base64, CLng("&o" & Mid(nGroup, 5, 2)) + 1, 1) + Mid(Base64, CLng("&o" & Mid(nGroup, 7, 2)) + 1, 1)
sOut = sOut + pOut
Next
Select Case Len(inData) Mod 3
Case 1: '8 bit final
sOut = Left(sOut, Len(sOut) - 2) + "=="
Case 2: '16 bit final
sOut = Left(sOut, Len(sOut) - 1) + "="
End Select
Base64Encode = sOut
End Function
Function Base64Decode(base64String)
'rfc1521
'1999 Antonin Foller, Motobit Software, http://Motobit.cz
Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXY
Dim dataLength, sOut, groupBegin
'remove white spaces, If any
base64String = Replace(base64String, vbCrLf, "")
base64String = Replace(base64String, vbTab, "")
base64String = Replace(base64String, " ", "")
'The source must consists from groups with Len of 4 chars
dataLength = Len(base64String)
If dataLength Mod 4 <> 0 Then
Err.Raise 1, "Base64Decode", "Bad Base64 string."
Exit Function
End If
' Now decode each group:
For groupBegin = 1 To dataLength Step 4
Dim numDataBytes, CharCounter, thisChar, thisData, nGroup, pOut
' Each data group encodes up To 3 actual bytes.
numDataBytes = 3
nGroup = 0
For CharCounter = 0 To 3
' Convert each character into 6 bits of data, And add it To
' an integer For temporary storage. If a character is a '=', there
' is one fewer data byte. (There can only be a maximum of 2 '=' In
' the whole string.)
thisChar = Mid(base64String, groupBegin + CharCounter, 1)
If thisChar = "=" Then
numDataBytes = numDataBytes - 1
thisData = 0
Else
thisData = InStr(1, Base64, thisChar, vbBinaryCompare) - 1
End If
If thisData = -1 Then
Err.Raise 2, "Base64Decode", "Bad character In Base64 string."
Exit Function
End If
nGroup = 64 * nGroup + thisData
Next
'Hex splits the long To 6 groups with 4 bits
nGroup = Hex(nGroup)
'Add leading zeros
nGroup = String(6 - Len(nGroup), "0") & nGroup
'Convert the 3 byte hex integer (6 chars) To 3 characters
pOut = Chr(CByte("&H" & Mid(nGroup, 1, 2))) + _
Chr(CByte("&H" & Mid(nGroup, 3, 2))) + _
Chr(CByte("&H" & Mid(nGroup, 5, 2)))
'add numDataBytes characters To out string
sOut = sOut & Left(pOut, numDataBytes)
Next
Base64Decode = sOut
End Function
%>