Results 1 to 18 of 18

Thread: [RESOLVED] Encrypt to readable string

  1. #1

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Resolved [RESOLVED] Encrypt to readable string

    hi guys! do you know of any algorithm that i can use to encrypt a string to a readable string so the result must be numeric (0-9) or Letters(Aa-Zz) or combination of the two. Thanks in advance!

  2. #2
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: Encrypt to readable string

    use this function:

    using System.Security.Cryptography;

    public static byte[] EncryptPassword(string userName, string password)
    {
    string tmpPassword = null;

    tmpPassword = userName.ToLower() + password;

    //Convert the password string into an Array of bytes.
    UTF8Encoding textConverter = new UTF8Encoding();
    byte[] passBytes = textConverter.GetBytes(tmpPassword);

    return new MD5CryptoServiceProvider().ComputeHash(passBytes);
    }
    *****************
    VB6,PHP,VS 2005

  3. #3
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Encrypt to readable string

    You are both speaking nonsense.

    daimous, it would seem that you need "base 36" encoding. Which is neither sensibly readable, nor encrypted to any strong degree.

    basti... hashing something drops its length. thus no encryption and no readibility.

  4. #4
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    354

    Re: Encrypt to readable string

    This is an off the shelf example from MSDN that was in vb and didn't work. I did some tweaking. This isn't exactly how you should encrypt things really securely, but it will get the job done. You need to read up on this stuff to identify the flaws in the code, but it is a good example to get you started in the basics.


    Everything should return in a string.


    Code:
    using System;
    using System.IO;
    using System.Security.Cryptography;
    using System.Text;
    
    
    namespace MyCrypto
    {
        /// <summary>
        /// 
        /// Class: Encrypt and Decrypt UTF strings
        /// Methods: encryptStringToBytes_AES, decryptStringFromBytes_AES,
        ///          getMD5HashString, getHashBytes
        /// 
        /// Key Length:
        /// 13/16/29 characters are needed for 128/152/256-bit 
        /// </summary>
        public class Crypto
        {
            
            protected Byte[] IV = {51, 129, 19, 159, 132, 55, 236, 179,
                                   89, 243, 244, 181, 17, 136, 39, 235}; 
            /// <summary>
            /// http://blog.brezovsky.net/en-text-2.html
            /// Returns same value as MD5() in PHP
            /// </summary>
            /// <param name="input"></param>
            /// <returns></returns>
            public string getMD5HashString(string sInput)
            {
                Byte[] bs = this.getHashBytes(sInput);
    
                StringBuilder s = new StringBuilder();
                foreach (byte b in bs)
                {
                    s.Append(b.ToString("x2").ToLower());
                }
                return s.ToString();
                
            }
    
            
            public Byte[] getHashBytes(string sInput)
            {
                MD5CryptoServiceProvider x = new MD5CryptoServiceProvider();
                byte[] bs = Encoding.UTF8.GetBytes(sInput);
                bs = x.ComputeHash(bs);
                return bs;
    
            }
    
            public string encryptStringToBytes_AES(string plainText, string sKey)
            {
                // Check arguments.
                if (plainText == null || plainText.Length <= 0)
                    throw new ArgumentNullException("plainText");
                if (sKey == null || sKey.Length <= 0)
                    throw new ArgumentNullException("Key");
    
    
                Byte[] byteKey = getHashBytes(sKey);
               
                // Declare the streams used
                // to encrypt to an in memory
                // array of bytes.
                MemoryStream msEncrypt = null;
                CryptoStream csEncrypt = null;
                StreamWriter swEncrypt = null;
    
                // Declare the RijndaelManaged object
                // used to encrypt the data.
                RijndaelManaged aesAlg = null;
    
                // Declare the bytes used to hold the
                // encrypted data.
                //byte[] encrypted = null;
    
                try
                {
                    // Create a RijndaelManaged object
                    // with the specified key and IV.
                    aesAlg = new RijndaelManaged();
                    aesAlg.Key = byteKey;
                    aesAlg.IV = IV;
    
                    // Create a decrytor to perform the stream transform.
                    ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
    
                    // Create the streams used for encryption.
                    msEncrypt = new MemoryStream();
                    csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write);
                    swEncrypt = new StreamWriter(csEncrypt);
    
                    //Write all data to the stream.
                    swEncrypt.Write(plainText);
    
                }
                finally
                {
                    // Clean things up.
    
                    // Close the streams.
                    if (swEncrypt != null)
                        swEncrypt.Close();
                    if (csEncrypt != null)
                        csEncrypt.Close();
                    if (msEncrypt != null)
                        msEncrypt.Close();
    
                    // Clear the RijndaelManaged object.
                    if (aesAlg != null)
                        aesAlg.Clear();
                }
    
                // Return the encrypted bytes from the memory stream.
                return Convert.ToBase64String(msEncrypt.ToArray());
    
            }
    
            public string decryptStringFromBytes_AES(string cipherText, string sKey)
            {
                // Check arguments.
                if (cipherText == null || cipherText.Length <= 0)
                    throw new ArgumentNullException("cipherText");
                if (sKey == null || sKey.Length <= 0)
                    throw new ArgumentNullException("Key");
    
                Byte[] cipherBytes = Convert.FromBase64String(cipherText);
                Byte[] byteKey = getHashBytes(sKey); 
    
                // TDeclare the streams used
                // to decrypt to an in memory
                // array of bytes.
                MemoryStream msDecrypt = null;
                CryptoStream csDecrypt = null;
                StreamReader srDecrypt = null;
    
                // Declare the RijndaelManaged object
                // used to decrypt the data.
                RijndaelManaged aesAlg = null;
    
                // Declare the string used to hold
                // the decrypted text.
                string plaintext = null;
    
                try
                {
                    // Create a RijndaelManaged object
                    // with the specified key and IV.
                    aesAlg = new RijndaelManaged();
                    aesAlg.Key = byteKey;
                    aesAlg.IV = IV;
    
                    // Create a decrytor to perform the stream transform.
                    ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
    
                    // Create the streams used for decryption.
                    msDecrypt = new MemoryStream(cipherBytes);
                    csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read);
                    srDecrypt = new StreamReader(csDecrypt);
    
                    // Read the decrypted bytes from the decrypting stream
                    // and place them in a string.
                    
                    plaintext = srDecrypt.ReadToEnd();
                }
                finally
                {
                    // Clean things up.
    
                    // Close the streams.
                    if (srDecrypt != null)
                        srDecrypt.Close();
                    if (csDecrypt != null)
                        csDecrypt.Close();
                    if (msDecrypt != null)
                        msDecrypt.Close();
    
                    // Clear the RijndaelManaged object.
                    if (aesAlg != null)
                        aesAlg.Clear();
                }
    
                return plaintext;
    
            }
    
    
        }//end class Crypto
    
    }//end MyCrypto

  5. #5
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Encrypt to readable string

    You could create a look-up table and do letter replacement (simple to design and implement)
    You could also go through and XOR by a set value (such as 32)
    There's dozens of ways to make it unreadable. Why does the result have to be a readable string? Are you transmitting it?
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  6. #6

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: Encrypt to readable string

    Thanks for the input guys! Actually, im trying to generate a unique key base from the unique ID and that generated key will to use to something like activation code. Currently i have this solution.
    First, generate a "unique" ID for a computer by getting some data about that computer like Drive C Serial, MAC Address, BIOS Serial, Memory Capacity
    Code:
            public string FuncGetSystemID()
            {
                string temp = string.Empty;
                StringBuilder SystemID = new StringBuilder();
                string DriveSerial = FuncGetDriveSerial();
                string MacAddress = FuncGetMACAddress();
                string BiosSerial = FuncGetBIOSSerial();
                string PMemoryCapacity = FuncGetPhysicalMemoryCapacity();
                int SysinfoLenght = DriveSerial.Length + MacAddress.Length + BiosSerial.Length + PMemoryCapacity.Length;
                //replace 16 with Sysinfolenght if you want to use teh full string lenght
                for (int i = 0; i < 20; i++)
                {
                    if ((i % 4) == 0 && i != 0)
                    {
                        SystemID.Append('-');
                    }
                    int counter = i % 4;
                    switch (counter)
                    {
                        case 0://Drive Serial
                            {
                                if ((i / 4) < DriveSerial.Length)
                                    SystemID.Append(DriveSerial.Substring((i / 4), 1));
                                else
                                    SystemID.Append(Convert.ToChar(i), 1);
                                    //SysinfoLenght++; uncomment is sysinfolenght will be use.
                                break;
                            }
                        case 1://MAC Address
                            {
                                if (((i - 1) / 4) < MacAddress.Length)
                                    SystemID.Append(MacAddress.Substring(((i - 1) / 4), 1));
                                else
                                    SystemID.Append(Convert.ToChar(i), 1);
                                break;
                            }
                        case 2://BIOSSerial
                            {
                                if (((i - 2) / 4) < BiosSerial.Length)
                                    SystemID.Append(BiosSerial.Substring(((i - 2) / 4), 1));
                                else
                                    SystemID.Append(Convert.ToChar(i), 1);
                                break;
                            }
                        case 3://Physical Memory Capacity
                            {
                                if (((i - 3) / 4) < PMemoryCapacity.Length)
                                    SystemID.Append(PMemoryCapacity.Substring(((i - 3) / 4), 1));
                                else
                                    SystemID.Append(Convert.ToChar(i), 1);
                                break;
                            }
                    }
    
                }
                return SystemID.ToString();
            }
    
            public string FuncGetDriveSerial()
            {
                string DriveCSerial = string.Empty;
                ManagementObject mobj = new ManagementObject("win32_logicaldisk.deviceid=\"C:\"");
                mobj.Get();
                DriveCSerial = mobj["VolumeSerialNumber"].ToString();
                mobj.Dispose();
                return DriveCSerial;
            }
    
            public string FuncGetMACAddress()
            {
                ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
                ManagementObjectCollection moc = mc.GetInstances();
                string MACAddress = String.Empty;
                foreach (ManagementObject mo in moc)
                {
                    if (MACAddress == String.Empty)  // only return MAC Address from first card
                    {
                        if ((bool)mo["IPEnabled"] == true) MACAddress = mo["MacAddress"].ToString();
                    }
                    mo.Dispose();
                }
                MACAddress = MACAddress.Replace(":", "");
                return MACAddress;
            }
    
            public string FuncGetBIOSSerial()
            {
                string BIOSSerial = string.Empty;
                ManagementObjectSearcher MgmtObjSearcher =
                    new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_BIOS");
    
                foreach (ManagementObject qryObj in MgmtObjSearcher.Get())
                {
    
                    BIOSSerial = qryObj["SerialNumber"].ToString();
                }
                return BIOSSerial;
            }
    
            public string FuncGetPhysicalMemoryCapacity()
            {
                string PhysicalMemoryCapacity = string.Empty;
              
                ManagementObjectSearcher searcher =
                    new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_PhysicalMemory");
    
                foreach (ManagementObject queryObj in searcher.Get())
                {
                    PhysicalMemoryCapacity = queryObj["Capacity"].ToString();
                }
                return PhysicalMemoryCapacity;
            }
    Second, Generate Unlock key/activation key from the generated ID
    Code:
            public string FuncGetunlockKey(string SystemId)
            {
                string TmpUnlockKey = string.Empty;
                string UnlockKey = string.Empty;
                string TmpKey = string.Empty;
                int counter = 1;
                UTF8Encoding encoder = new UTF8Encoding();
                MD5 md5 = new MD5CryptoServiceProvider();
                byte[] result = md5.ComputeHash(encoder.GetBytes(SystemId));
                foreach (byte b in result)
                {
                    TmpUnlockKey += b.ToString();
                }
    
                foreach (char chr in TmpUnlockKey)
                {                
                    TmpKey += chr.ToString();
                    if (counter == 2)
                    {
                        int i;
                        int.TryParse(TmpKey,out i);
                        if ((i >= 48 && i <= 57) || (i >= 65 && i <= 90) || (i >= 97 && i <= 122))
                        {
                            UnlockKey += Convert.ToChar(i);
                        }
                        else
                        {
                            UnlockKey += TmpKey;
                        }
                        counter = 0;
                        TmpKey = "";
                    }
                    counter++;
                }
    
                return UnlockKey;
            }
    Comments, suggestion, critcism will be highly appreciate. Thanks!

  7. #7
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    354

    Re: Encrypt to readable string


  8. #8
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: Encrypt to readable string

    I read all the comments and I'm a little confused as to exactly what you want. But anyway, I don't know if an encryption like 3DES or Triple DES would help you. There's a complete example in the msdn. With these type of encryption algorithms, a string is excrypted and returned an array of bytes. I simply convert the array of bytes back to a string if the need arises.

    Hope this helps - Jennifer.

  9. #9
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: Encrypt to readable string

    Quote Originally Posted by wossname
    You are both speaking nonsense..
    I sometimes see some people attempt to help others in here and someone else comes along with harsh words either because their input was slighty incorrect or whatever... The point is that somebody tried. So all I would say is: I think you need to refine you communication skills!

    Jennifer.

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Encrypt to readable string

    But if it doesn't work, then it's not really any help then is it? IT just becomes noise that leads to further problems.

    And all basti did was to take username and password, concat them, then hashed it. Hardly satisfying the requirements that it be "readable" (which doesn't make much sense to me either.)

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Encrypt to readable string

    Quote Originally Posted by JenniferBabe
    I sometimes see some people attempt to help others in here and someone else comes along with harsh words either because their input was slighty incorrect or whatever... The point is that somebody tried. So all I would say is: I think you need to refine you communication skills!

    Jennifer.
    In what way was it harsh? It was a statement of fact. Also those living in glass houses shouldn't throw stones etc...
    I don't live here any more.

  12. #12
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Encrypt to readable string

    or use the toilet. It looks like des isn't what he wants. He's trying to come up with a way to generate registration keys (correct me if wrong)
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  13. #13
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    354

    Re: Encrypt to readable string

    Quote Originally Posted by Lord Orwell
    or use the toilet. It looks like des isn't what he wants. He's trying to come up with a way to generate registration keys (correct me if wrong)
    nope that what I gathered after he posted his code. His problem is he doesn't know how to convery in proper terms what he wants.

  14. #14

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: Encrypt to readable string

    My problem is already solved with the help of you guys...Thanks very much for the ideas.

  15. #15
    Junior Member
    Join Date
    Jun 2007
    Posts
    26

    Re: [RESOLVED] Encrypt to readable string

    if you don't have an obfuscator, there's no use in encryption. Although .net applications cannot be opened in ollydbg, there are much easier and more efficient ways of disassembling such as reflector...using this allows someone to just about view your original source...so either use encryption and an obfuscator or use neither...

  16. #16

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: [RESOLVED] Encrypt to readable string

    You right! Ive tested it my self with Reflector and i can easily view the code and worse even my function to generate a valid code which i dont want to heppen....I think i need to post this issue as new Thread since this is a different issue. Thanks alot gamesguru!

  17. #17
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: [RESOLVED] Encrypt to readable string

    what is this Reflector? Is it a .net component?
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  18. #18
    Junior Member
    Join Date
    Jun 2007
    Posts
    26

    Re: [RESOLVED] Encrypt to readable string

    Reflector is a .NET disassembler. It allows you to view, basically, the exact source used to compile that class library or application. It was a real shocker to me to find out that you could do that...there's many look alike programs too, but most are not free. There's also one in visual studios! If you can believe that...but reflector is my personal favorite...and obfuscators can't fully protect you, it will not stop the determined cracker...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width