Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP.NET (Non-Forum Related)
 Does anyone have a c# port of the password...
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

CarKnee
Junior Member

USA
297 Posts

Posted - 20 November 2005 :  21:04:53  Show Profile  Visit CarKnee's Homepage
Is there any shot of someone having a c# port of the algo used to generate the password for Snitz users?

My new site is in .NET/C# and I wanted to:
1. Stay with a very minimal forum running on Access. CommunityServer and the like are way to complex for what I am looking to do.

2. I do not want to build my site around the Snitz DB schema. I just need a c# password port so I can insert my current users into the Snitz DB.

Thanks!
CarKnee




Edited by - Da_Stimulator on 05 March 2006 23:37:47

pdrg
Support Moderator

United Kingdom
2897 Posts

Posted - 21 November 2005 :  07:19:39  Show Profile  Send pdrg a Yahoo! Message
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemsecuritycryptographysha256classtopic.asp any use?
Go to Top of Page

Podge
Support Moderator

Ireland
3775 Posts

Posted - 21 November 2005 :  08:27:42  Show Profile  Send Podge an ICQ Message  Send Podge a Yahoo! Message
VB.net

Public Function SHA256Hash(ByVal InputStr As String) As String
        Dim SHA256Hasher As New System.Security.Cryptography.SHA256Managed
        Return LCase$(ToHexString(SHA256Hasher.ComputeHash(Encoder.GetBytes(InputStr))))
    End Function

    Private Function ToHexString(ByVal ByteArray As Byte()) As String
        Dim i As Integer
        For i = LBound(ByteArray) To UBound(ByteArray)
            If Len(Hex(ByteArray(i))) = 1 Then
                ToHexString &= "0" & LCase$(Hex(ByteArray(i)))
            Else
                ToHexString &= LCase$(Hex(ByteArray(i)))
            End If
        Next
    End Function


C#.NET (Untested)

public string SHA256Hash(string InputStr) 
{ 
 System.Security.Cryptography.SHA256Managed SHA256Hasher = new System.Security.Cryptography.SHA256Managed(); 
 return LCase(ToHexString(SHA256Hasher.ComputeHash(Encoder.GetBytes(InputStr)))); 
} 

private string ToHexString(byte[] ByteArray) 
{ 
 int i; 
 for (int i = LBound(ByteArray); i <= UBound(ByteArray); i++) { 
   if (Len(Hex(ByteArray(i))) == 1) { 
     ToHexString += "0" + LCase(Hex(ByteArray(i))); 
   } else { 
     ToHexString += LCase(Hex(ByteArray(i))); 
   } 
 } 
}

Podge.

The Hunger Site - Click to donate free food | My Blog | Snitz 3.4.05 AutoInstall (Beta!)

My Mods: CAPTCHA Mod | GateKeeper Mod
Tutorial: Enable subscriptions on your board

Warning: The post above or below may contain nuts.
Go to Top of Page

CarKnee
Junior Member

USA
297 Posts

Posted - 21 November 2005 :  19:13:31  Show Profile  Visit CarKnee's Homepage
Thanks for the reply, and I kew I should have mentioned this, but the buit in SHA256 does NOT match up with what Snitz uses.

Go to Top of Page

Podge
Support Moderator

Ireland
3775 Posts

Posted - 22 November 2005 :  03:33:36  Show Profile  Send Podge an ICQ Message  Send Podge a Yahoo! Message
I have used the vb one above for some time without problem. Do you have examples where the Snitz sha function returns a different hash than the above code?

Podge.

The Hunger Site - Click to donate free food | My Blog | Snitz 3.4.05 AutoInstall (Beta!)

My Mods: CAPTCHA Mod | GateKeeper Mod
Tutorial: Enable subscriptions on your board

Warning: The post above or below may contain nuts.
Go to Top of Page

pdrg
Support Moderator

United Kingdom
2897 Posts

Posted - 22 November 2005 :  03:57:41  Show Profile  Send pdrg a Yahoo! Message
Blimey - if that's a .NET bug let me know immediately and I'll raise it with the product teams - if it's a flawed implementation in Snitz, that's bad, but I doubt we can change the code for fear of locking everyone out of their forums now!

BTW if you can do a VB.NET port of the code based on the ASP/VBScript version, you should be able to use that natively in your C# project as long as you tell the compiler it's a VB.NET bit - may make your life easier?
Go to Top of Page

Podge
Support Moderator

Ireland
3775 Posts

Posted - 22 November 2005 :  08:06:17  Show Profile  Send Podge an ICQ Message  Send Podge a Yahoo! Message
I doubt its a bug. I do remember though when I wrote the vb.net function that there were differences between the Snitz implementation and the standard hash that dotnet creates. I had to alter the function in order to add leading zero's for single digit bits when creating the hexString. This could be causing the problem.

Realnus posted a problem with it when using Turkish characters so there could also be a problem with non-English characters too - http://forum.snitz.com/forum/topic.asp?TOPIC_ID=59581

If I had samples of the unencrypted, Snitz encrypted and vb.net encrypted passwords it would help identify the problem.

Podge.

The Hunger Site - Click to donate free food | My Blog | Snitz 3.4.05 AutoInstall (Beta!)

My Mods: CAPTCHA Mod | GateKeeper Mod
Tutorial: Enable subscriptions on your board

Warning: The post above or below may contain nuts.
Go to Top of Page

CarKnee
Junior Member

USA
297 Posts

Posted - 22 November 2005 :  09:02:45  Show Profile  Visit CarKnee's Homepage
What type of encoding are you using for "Encoder"?

I am assuming System.Text.UnicodeEncoding
If it is a different one, that may explain the difference


Edited by - CarKnee on 22 November 2005 09:03:50
Go to Top of Page

CarKnee
Junior Member

USA
297 Posts

Posted - 22 November 2005 :  09:30:48  Show Profile  Visit CarKnee's Homepage
Here are some strings (int) I ran through each function.


string | Podges Function | Snitz

0       e4f60d0aa6d7f3d3b6a6494b1c861b99f649c6f9ec51abaf201b20f297327c95	5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9
1       e79e418e48623569d75e2a7b09ae88ed9b77b126a445b9ff9dc6989a08efa079	6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b
2       913da1f8df6f8fd47593840d533ba0458cc9873996bf310460abb495b34c232a	d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35
3       ac11339ffa8f270c4f781e0a3922bb1c80d9dee6e4b6911ca34538ed9ae03caa	4e07408562bedb8b60ce05c1decfe3ad16b72230967de01f640b7e4729b49fce
4       3089c464221340fed4229d6ba913a04224c91b44158c22163e8849eb7dcc4878	4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a
5       166f829e016f2315a8099e3a8d2dbec6d91572379ff02c760ba4e0335789d47f	ef2d127de37b942baad06145e54b0c619a1f22327b2ebbcfbec78f5564afe39d
6       aa4fb8a61cab7db73f42671f2bb987a7291a436929b3d5f17ffe05f96be13371	e7f6c011776e8db7cd330b54174fd76f7d0216b612387a5ffcfb81e6f0919683
7       bb153e97380f82aa57033add2c11b28a3ae640c8daaa89d2bd5bd317456ecb03	7902699be42c8a8e46fbbb4501726517e86b22c56a189f7625a6da49081b2451
8       0c59629d81806b2b169bcd633f8a9cb7da43a8d692dbc95bc201d0f5cf5e08d5	2c624232cdd221771294dfbb310aca000a0df6ac8b66b696d90ef06fdefb64a3
9       b58d15e89a953322b7ac8fc0d6e37710c1eacd25d8304efd002904cb18ef62c6	19581e27de7ced00ff1ce50b2047e7a567c76b1cbaebabe5ef03f7c3017bb5b7
10      6293cfd466c303614e6d60a7bb6f33aaec14bf2f00a267138e324113874aa0f6	4a44dc15364204a80fe80e9039455cc1608281820fe2b24f1e5233ade6af1dd5
11      a4d88ccad29017fc73b20a50743aefbff5486fe6190f8457eff4eeb2cf6a4c97	4fc82b26aecb47d2868c4efbe3581732a3e7cbcc6c2efb32062c08170a05eeb8
12      7fe63d4f5cdb7d94fc8c9d51c372aa4a104bbdd42082ac1866a16dc399fe3d4f	6b51d431df5d7f141cbececcf79edf3dd861c3b4069f0b11661a3eefacbba918
13      aa3f6a104315ed49148b29185f7120f5a29c784dfb489cb0e96e7866cf066a7a	3fdba35f04dc8c462986c992bcf875546257113072a909c162f7e470e581e278
14      691251b8ae6af82e999421c3f7596a7149ccb38d2e70a7ebf7e8cd17e2401b89	8527a891e224136950ff32ca212b45bc93f69fbb801c3b1ebedac52775f99e61
15      31641e81a596de050fb5892f54bcc64235744c761618b91ded409b2f4eabb4b5	e629fa6598d732768f7c726b4b621285f9c3b85303900aa912017db7617d8bdb
16      1b830ead18ff2052520ea9ebae9ebd3a24091600ad6ba3867431ba3d540d40bc	b17ef6d19c7a5b1ee83b907c595526dcb1eb06db8227d650d5dda0a9f4ce8cd9
17      cc50dd8b83673e2c208e6c7f86fc5d7f6ccbaf3a7b99ccbdb589f1a56c772e89	4523540f1504cd17100c4835e85b7eefd49911580f8efff0599a8f283be6b9e3
18      a40d848fef41a4a5232187c6f23c2ca8a6cf03e94617076ffb951b0cecae68fd	4ec9599fc203d176a301536c2e091a19bc852759b255bd6818810a42c5fed14a
19      725b61eaa9973f5ef7fe6be2033c5f264982c8c04ed318a169bb2169486b1565	9400f1b21cb527d7fa3d3eabba93557a18ebe7a2ca4e471cfe5e4c5b4ca7f767
20      2e5538b27532ebabc981a457a9a1a7feb3778802d8237420fc17d428b58fcaea	f5ca38f748a1d6eaf726b8a42fb575c3c71f1864a8143301782de13da2d9202b
21      d74a4bce415facd50d7d8a0daf6f99a2b3c500072e31f9d31d0ec29edc096f3b	6f4b6612125fb3a0daecd2799dfd6c9c299424fd920f9b308110a2c1fbd8f443
22      19edc590981135ff87d34a277ac5e3f37a68bdf2c65917cd83be81dfea94b385	785f3ec7eb32f30b90cd0fcf3657d388b5ff4297f2f9716ff66e9b69c05ddd09
23      7629c23f2b4db224da2f397a2b76d99c527b15a62f079da59909f0ded2750bb0	535fa30d7e25dd8a49f1536779734ec8286108d115da5045d77f3b4185d8f790
24      c8c5d47006b43a3b4e5a2446613696242d01b7b6236d2311dc19a4e650eaa8ac	c2356069e9d1e79ca924378153cfbbfb4d4416b1f99d41a2940bfdb66c5319db
25      5b451ac13f7aea73e64b6d4a626022c5b0d30dc4a457a1dec24f6468a10a20f4	b7a56873cd771f2c446d369b649430b65a756ba278ff97ec81bb6f55b2e73569




Podge's Code:

Public Class SnitzEncryption

    Public Shared Function SHA256Hash(ByVal InputStr As String) As String
        Dim SHA256Hasher As New System.Security.Cryptography.SHA256Managed
        Dim Encoder As New System.Text.UnicodeEncoding
        Return LCase$(ToHexString(SHA256Hasher.ComputeHash(Encoder.GetBytes(InputStr))))
    End Function

    Public Shared Function ToHexString(ByVal ByteArray As Byte()) As String
        Dim i As Integer
        For i = LBound(ByteArray) To UBound(ByteArray)
            If Len(Hex(ByteArray(i))) = 1 Then
                ToHexString &= "0" & LCase$(Hex(ByteArray(i)))
            Else
                ToHexString &= LCase$(Hex(ByteArray(i)))
            End If
        Next
    End Function

End Class

I call that by:
for (int i = 0; i< 100; i++)
{
   Console.WriteLine(i.ToString() + "\t" + SnitzEncrypt.SnitzEncryption.SHA256Hash(i.ToString()));
}


ASP Code:

<!-- #include file="inc_sha256.asp" -->
<%

for i = 0 to 100
   Response.write SHA256(i) & VbNewLine
Next

%>


Edited by - CarKnee on 22 November 2005 09:36:43
Go to Top of Page

Podge
Support Moderator

Ireland
3775 Posts

Posted - 22 November 2005 :  10:24:43  Show Profile  Send Podge an ICQ Message  Send Podge a Yahoo! Message
hmmm...

When I get home I'll look up the function which I know worked for me in the past.

Podge.

The Hunger Site - Click to donate free food | My Blog | Snitz 3.4.05 AutoInstall (Beta!)

My Mods: CAPTCHA Mod | GateKeeper Mod
Tutorial: Enable subscriptions on your board

Warning: The post above or below may contain nuts.
Go to Top of Page

CarKnee
Junior Member

USA
297 Posts

Posted - 22 November 2005 :  10:42:52  Show Profile  Visit CarKnee's Homepage
I did modify your function a bit since you have "Encoder" outside of your function.

Thanks for your help!

Public Shared Function SHA256Hash(ByVal InputStr As String) As String
Dim SHA256Hasher As New System.Security.Cryptography.SHA256Managed
Dim Encoder As New System.Text.UnicodeEncoding
Return LCase$(ToHexString(SHA256Hasher.ComputeHash(Encoder.GetBytes(InputStr))))
End Function


Edited by - CarKnee on 22 November 2005 10:43:35
Go to Top of Page

Podge
Support Moderator

Ireland
3775 Posts

Posted - 22 November 2005 :  11:50:28  Show Profile  Send Podge an ICQ Message  Send Podge a Yahoo! Message
I have it declared as

Dim Encoder As New System.Text.ASCIIEncoding

Podge.

The Hunger Site - Click to donate free food | My Blog | Snitz 3.4.05 AutoInstall (Beta!)

My Mods: CAPTCHA Mod | GateKeeper Mod
Tutorial: Enable subscriptions on your board

Warning: The post above or below may contain nuts.
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 22 November 2005 :  11:54:01  Show Profile  Visit HuwR's Homepage
try this


public static string SHA256Hash(string Data)
{
        SHA256 sha = new SHA256Managed();
        byte[] hash = sha.ComputeHash( Encoding.ASCII.GetBytes(Data) );

        StringBuilder stringBuilder = new StringBuilder();
        foreach( byte b in hash ) 
        {
            stringBuilder.AppendFormat("{0:x2}", b);
        }
        return stringBuilder.ToString();
    }
Go to Top of Page

CarKnee
Junior Member

USA
297 Posts

Posted - 22 November 2005 :  12:56:09  Show Profile  Visit CarKnee's Homepage
HuwR, That is almost identical to what I have been using in other apps for a while now. The only difference is I have always used Unicode when I should have been using ASCII.

Thanks to all it works well now.

Go to Top of Page

pdrg
Support Moderator

United Kingdom
2897 Posts

Posted - 23 November 2005 :  10:39:42  Show Profile  Send pdrg a Yahoo! Message
Ahhhh - Unicode vs ASCII - these will be two VERY different strings, hence 2 very different hashes (the Unicode string uses 2 bytes for each character, ASCII only 1 byte). Worth understanding the difference, how they're implemented, and hence when to use NVARCHARs and when to use VARCHARs!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.13 seconds. Powered By: Snitz Forums 2000 Version 3.4.07