Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
MD5 encryption
Message
De
26/10/2012 05:16:20
 
 
À
26/10/2012 05:08:39
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Versions des environnements
SQL Server:
SQL Server 2008
Divers
Thread ID:
01555853
Message ID:
01555855
Vues:
53
>>Hi
>>
>>I'm being passed some data encrypted with MD5.
>>
>>I can find examples of how I encrypt in TSql
>>
>>SELECT CONVERT(NVARCHAR(32),HashBytes('MD5', 'email@dot.com'),2)
>>
>>but I can't find an example of how I would de encrypt the result to get the original content.
>
>You can't - it's just a hash value....

Hi Viv

I'm being passed some data which I've been told is MD5 encrpted

they've also passed me some c# code which has encryption and decryption functions.

Is that not the same thing ?

Nick


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace Unified.ram.Common.Util
{
public class EncryptDecrypt
{
public static string Encrypt(string strToEncrypt)
{
string key = Sitecore.Configuration.Settings.GetSetting("EncryptDecryptKey", "");
return Encrypt(strToEncrypt, key);
}

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;
}
}

public static string Decrypt(string strEncrypted)
{
string key = Sitecore.Configuration.Settings.GetSetting("EncryptDecryptKey", "");
return Decrypt(strEncrypted, key);
}

public static string Decrypt(string strEncrypted, 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 = Convert.FromBase64String(strEncrypted);
string strDecrypted = ASCIIEncoding.ASCII.GetString
(objDESCrypto.CreateDecryptor().TransformFinalBlock
(byteBuff, 0, byteBuff.Length));
objDESCrypto = null;
return strDecrypted;
}
catch (Exception ex)
{
return "Wrong Input. " + ex.Message;
}
}
}
}
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform