kelvinfix
kelvinfix

Reputation: 3075

Create unique encryption

It is use to encrypt a string to create a unique fingerprint like 8FAC-5806-FF54-4174-F89E-43DE-97A6-5648.

How can I convert it back from the 8FAC-5806-FF54-4174-F89E-43DE-97A6-5648 to the string?

MD5 is single encryption, so have to use tripleDES to retrieve it back. but how to create a string like this 8FAC-5806-FF54-4174-F89E-43DE-97A6-5648 using the method below:

public static string Encrypt(string strToEncrypt, string strKey)
    {
        try
        {
            TripleDESCryptoServiceProvider objDESCrypto = new TripleDESCryptoServiceProvider();
            MD5CryptoServiceProvider objHashMD5 = new MD5CryptoServiceProvider();

            byte[] byteHash, byteBuff;
            string strTempKey = strKey;

            byteHash = objHashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(strTempKey));
            objHashMD5 = null;
            objDESCrypto.Key = byteHash;
            objDESCrypto.Mode = CipherMode.ECB; //CBC, CFB

            byteBuff = ASCIIEncoding.ASCII.GetBytes(strToEncrypt);
            return Convert.ToBase64String(objDESCrypto.CreateEncryptor().TransformFinalBlock(byteBuff, 0, byteBuff.Length));
        }
        catch (Exception ex)
        {
            return "Wrong Input. " + ex.Message;
        }
    }

Upvotes: 0

Views: 250

Answers (1)

dtb
dtb

Reputation: 217361

The code uses MD5 to generate the fingerprint. MD5 is a one-way hashing algorithm. This means that it's not possible to reverse the algorithm to get the original value back. Hashing is not encryption. If you want to encrypt your string and be able to decrypt it, you need to use an encryption algorithm such as AES.

Upvotes: 5

Related Questions