|
security
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Upgrading Encryption to .Net not Working!!!!!!!I am using the following the code below in VB6: Public Function EncryptPassword(ByVal Password As String) As String Dim objEncoder As BX_BCA.Encoder Dim objProviders As BX_BCA.clsProviders Dim objHash As BX_BCA.clsHash Dim lngProviderID As Long Dim abytPassword() As Byte Set objEncoder = New BX_BCA.Encoder abytPassword() = objEncoder.stringToByteArray(strPassword) Set objProviders = New BX_BCA.clsProviders lngProviderID = objProviders.LocateProvider("Microsoft Enhanced Cryptographic Provider v1.0", ProviderTypes.PROV_RSA_FULL) Call objProviders.Item(lngProviderID).Acquire(Flags:=CRYPT_VERIFYCONTEXT) Set objHash = objProviders.Item(lngProviderID).CreateHash(HashTypes.CALG_MD5) Call objHash.AddData(abytPassword()) EncryptPassword = objHash.ToHex End Sub I used an MSDN article to create an ecryption routine under C# but it isn't being accepted by the app: public string EncryptPassword(string passWord) { MD5CryptoServiceProvider cryptoService; try { byte[] bytValue; byte[] bytHash; // Create New Crypto Service Provider Object cryptoService=new MD5CryptoServiceProvider(); // Convert the original string to array of Bytes bytValue = Encoding.UTF8.GetBytes(passWord); // Compute the Hash, returns an array of Bytes bytHash = cryptoService.ComputeHash(bytValue); cryptoService.Clear(); // Return a base 64 encoded string of the Hash value return Convert.ToBase64String(bytHash); Any ideas? Your VB code is returning the hash in hex, while your C# code is
returning it as a Base64 encoded string. Try this: ------------------------- StringBuilder hexVal = new StringBuilder(); foreach (byte b in bytHash) { hexVal.Append(b.ToString("X")); } string bytHashInHex = hexVal.ToString(); ------------------------- return bytHashInHex instead of Convert.ToBase64String(bytHash) HTH Your VB code is returning the hash in hex, while your C# code is
returning it as a Base64 encoded string. Try this: ------------------------- StringBuilder hexVal = new StringBuilder(); foreach (byte b in bytHash) { hexVal.Append(b.ToString("X")); } ------------------------- return hexVal.ToString() instead of Convert.ToBase64String(bytHash) HTH Hey Swat,
That was one thought I had. As it turns out, below is what I needed: string encrypted= System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(passWord,"md5"); Regards, TC Show quoteHide quote "swat" <loka_1***@yahoo.com> wrote in message news:1114438291.499174.280750@o13g2000cwo.googlegroups.com... > Your VB code is returning the hash in hex, while your C# code is > returning it as a Base64 encoded string. > > Try this: > ------------------------- > StringBuilder hexVal = new StringBuilder(); > foreach (byte b in bytHash) > { > hexVal.Append(b.ToString("X")); > } > ------------------------- > > return hexVal.ToString() instead of Convert.ToBase64String(bytHash) > > > HTH >
Encrypt with RijndaelManaged and decrypt with OpenSSL
UIPermission Clipboard IsAuthenticated property on IIdentity interface running dll from a network share Event Log Write access under ASP.NET Windows Authentication Newbie Question Access denied with interop Windows security context Help needed with TSL problem. AzMan - ADAM store. |
|||||||||||||||||||||||