Please Help - Encryption Problems

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Please Help - Encryption Problems

    Hi,
    I have a problem in that I have 2 applications writing to the same Database.
    One App is web based and the other is windows/forms based.
    Both have the same job in that they can reset a users password in the
    database. Both are using SHA1 encryption however they both ghive different
    results when the programs are run.
    If I run the windows exe file and set the password to password the exe
    encrypts as follows: 5BAA61E4C9B93F3F68225B6CF8331B7EE68FD8

    If I run the web based version with the word password I get the following:
    5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8

    Notice the web version has extra in it.
    Please help..... Below is the code I have been using for both versions:

    Web Version:
    Dim PwdAs String = "password"
    Dim hashedPwd As String =
    FormsAuthentication.HashPasswordForStoringInConfig File(Pwd, "SHA1")
    Return hashedPwd


    Windows Exe Version:
    Dim PwdAs String = Trim("password")
    Dim Data As Byte()
    Data = System.Text.Encoding.ASCII.GetBytes(Pwd)
    Dim shaM As New SHA1Managed
    Dim resultHash As Byte() = shaM.ComputeHash(Data)
    Dim hashedpwd = ""
    Dim b As Byte
    For Each b In resultHash
    hashedpwd += Hex(b)
    Next
    Return hashedpwd


    Thanks
    Jamie


    Jamie Sutherland Guest

  2. Similar Questions and Discussions

    1. 128 Bit AES Encryption
      Hi All, Is it possible to implement 128 bit AES encryption in coldfusion 5.0? Regards cfdyn
    2. URL Encryption
      Hi, Is there a way to securely ecrypt and decrypte a URL? for e.g encrypting and decrypting using Triple-DES algorithm. Are there any security...
    3. IDS 9.40.UC2, Encryption
      I try to configure encryption with IDS 9.40.UC2 on an AIX platform and I'm a little bit confused about the different error messages I receive. ...
    4. Help with encryption
      Thanks in advance for your assistance. I have all my personal files encrypted on a separate hd on my home pc. The OS(Windows XP PRO) resides with...
    5. 128 bit encryption problems
      i am currently running windows xp home edition on a compaq computer. it has been relatively troublefree until recently. this computer (and only...
  3. #2

    Default Re: Please Help - Encryption Problems

    It is probably an encoding problem. Forms auth uses UTF8 encoding and you
    are using ASCII. I suggest you try switching to UTF8 first.

    Joe K.

    "Jamie Sutherland" <jamie.sutherland@nhcscotland.no.spam.com> wrote in
    message news:eH30GnTKEHA.3380@TK2MSFTNGP09.phx.gbl...
    > Hi,
    > I have a problem in that I have 2 applications writing to the same
    Database.
    > One App is web based and the other is windows/forms based.
    > Both have the same job in that they can reset a users password in the
    > database. Both are using SHA1 encryption however they both ghive different
    > results when the programs are run.
    > If I run the windows exe file and set the password to password the exe
    > encrypts as follows: 5BAA61E4C9B93F3F68225B6CF8331B7EE68FD8
    >
    > If I run the web based version with the word password I get the following:
    > 5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8
    >
    > Notice the web version has extra in it.
    > Please help..... Below is the code I have been using for both versions:
    >
    > Web Version:
    > Dim PwdAs String = "password"
    > Dim hashedPwd As String =
    > FormsAuthentication.HashPasswordForStoringInConfig File(Pwd, "SHA1")
    > Return hashedPwd
    >
    >
    > Windows Exe Version:
    > Dim PwdAs String = Trim("password")
    > Dim Data As Byte()
    > Data = System.Text.Encoding.ASCII.GetBytes(Pwd)
    > Dim shaM As New SHA1Managed
    > Dim resultHash As Byte() = shaM.ComputeHash(Data)
    > Dim hashedpwd = ""
    > Dim b As Byte
    > For Each b In resultHash
    > hashedpwd += Hex(b)
    > Next
    > Return hashedpwd
    >
    >
    > Thanks
    > Jamie
    >
    >

    Joe Kaplan \(MVP - ADSI\) Guest

  4. #3

    Default Re: Please Help - Encryption Problems

    I agree with Joe suggestion.
    FormsAuthentication.HashPasswordForStoringInConfig File method actually
    encode in UTF8 and not in ASCII as you do in the WinForms scenario. BTW, I
    suggest to use the same methods for both clients
    (HashPasswordForStoringInConfigFile should be well suited in this case).
    However, if you are hashing passwords for storing in a DB, I recommend you
    to add a salt value for dictionary attacks mitigation. Check out this code
    from
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetch12.asp:[/url]

    Creating a Salt Value
    The following code shows how to generate a salt value by using random number
    generation functionality provided by the RNGCryptoServiceProvider class
    within the System.Security.Cryptography namespace.

    public static string CreateSalt(int size)
    {
    RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
    byte[] buff = new byte[size];
    rng.GetBytes(buff);
    return Convert.ToBase64String(buff);
    }Creating a Hash Value (with Salt)
    The following code fragment shows how to generate a hash value from a
    supplied password and salt value.

    public static string CreatePasswordHash(string pwd, string salt)
    {
    string saltAndPwd = string.Concat(pwd, salt);
    string hashedPwd =
    FormsAuthentication.HashPasswordForStoringInConfig File(
    saltAndPwd, "SHA1");
    return hashedPwd;
    }


    --
    Hernan de Lahitte
    Lagash Systems S.A.
    [url]http://weblogs.asp.net/hernandl[/url]


    This posting is provided "AS IS" with no warranties, and confers no rights.

    "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com> wrote
    in message news:%23jvEnWUKEHA.3924@tk2msftngp13.phx.gbl...
    > It is probably an encoding problem. Forms auth uses UTF8 encoding and you
    > are using ASCII. I suggest you try switching to UTF8 first.
    >
    > Joe K.
    >
    > "Jamie Sutherland" <jamie.sutherland@nhcscotland.no.spam.com> wrote in
    > message news:eH30GnTKEHA.3380@TK2MSFTNGP09.phx.gbl...
    > > Hi,
    > > I have a problem in that I have 2 applications writing to the same
    > Database.
    > > One App is web based and the other is windows/forms based.
    > > Both have the same job in that they can reset a users password in the
    > > database. Both are using SHA1 encryption however they both ghive
    different
    > > results when the programs are run.
    > > If I run the windows exe file and set the password to password the exe
    > > encrypts as follows: 5BAA61E4C9B93F3F68225B6CF8331B7EE68FD8
    > >
    > > If I run the web based version with the word password I get the
    following:
    > > 5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8
    > >
    > > Notice the web version has extra in it.
    > > Please help..... Below is the code I have been using for both versions:
    > >
    > > Web Version:
    > > Dim PwdAs String = "password"
    > > Dim hashedPwd As String =
    > > FormsAuthentication.HashPasswordForStoringInConfig File(Pwd, "SHA1")
    > > Return hashedPwd
    > >
    > >
    > > Windows Exe Version:
    > > Dim PwdAs String = Trim("password")
    > > Dim Data As Byte()
    > > Data = System.Text.Encoding.ASCII.GetBytes(Pwd)
    > > Dim shaM As New SHA1Managed
    > > Dim resultHash As Byte() = shaM.ComputeHash(Data)
    > > Dim hashedpwd = ""
    > > Dim b As Byte
    > > For Each b In resultHash
    > > hashedpwd += Hex(b)
    > > Next
    > > Return hashedpwd
    > >
    > >
    > > Thanks
    > > Jamie
    > >
    > >
    >
    >

    Hernan de Lahitte Guest

  5. #4

    Default Re: Please Help - Encryption Problems

    I also agree with Hernan in that adding random salt is very important to
    prevent dictionary attacks. There have been some excellent articles written
    on this topic recently.

    Joe K.

    "Hernan de Lahitte" <hernan@lagash.com> wrote in message
    news:%23cXrhBVKEHA.3704@TK2MSFTNGP11.phx.gbl...
    > I agree with Joe suggestion.
    > FormsAuthentication.HashPasswordForStoringInConfig File method actually
    > encode in UTF8 and not in ASCII as you do in the WinForms scenario. BTW, I
    > suggest to use the same methods for both clients
    > (HashPasswordForStoringInConfigFile should be well suited in this case).
    > However, if you are hashing passwords for storing in a DB, I recommend you
    > to add a salt value for dictionary attacks mitigation. Check out this code
    > from
    >
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetch12.asp:[/url]
    >
    > Creating a Salt Value
    > The following code shows how to generate a salt value by using random
    number
    > generation functionality provided by the RNGCryptoServiceProvider class
    > within the System.Security.Cryptography namespace.
    >
    > public static string CreateSalt(int size)
    > {
    > RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
    > byte[] buff = new byte[size];
    > rng.GetBytes(buff);
    > return Convert.ToBase64String(buff);
    > }Creating a Hash Value (with Salt)
    > The following code fragment shows how to generate a hash value from a
    > supplied password and salt value.
    >
    > public static string CreatePasswordHash(string pwd, string salt)
    > {
    > string saltAndPwd = string.Concat(pwd, salt);
    > string hashedPwd =
    > FormsAuthentication.HashPasswordForStoringInConfig File(
    > saltAndPwd, "SHA1");
    > return hashedPwd;
    > }
    >
    >
    > --
    > Hernan de Lahitte
    > Lagash Systems S.A.
    > [url]http://weblogs.asp.net/hernandl[/url]
    >
    >
    > This posting is provided "AS IS" with no warranties, and confers no
    rights.
    >
    > "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com> wrote
    > in message news:%23jvEnWUKEHA.3924@tk2msftngp13.phx.gbl...
    > > It is probably an encoding problem. Forms auth uses UTF8 encoding and
    you
    > > are using ASCII. I suggest you try switching to UTF8 first.
    > >
    > > Joe K.
    > >
    > > "Jamie Sutherland" <jamie.sutherland@nhcscotland.no.spam.com> wrote in
    > > message news:eH30GnTKEHA.3380@TK2MSFTNGP09.phx.gbl...
    > > > Hi,
    > > > I have a problem in that I have 2 applications writing to the same
    > > Database.
    > > > One App is web based and the other is windows/forms based.
    > > > Both have the same job in that they can reset a users password in the
    > > > database. Both are using SHA1 encryption however they both ghive
    > different
    > > > results when the programs are run.
    > > > If I run the windows exe file and set the password to password the exe
    > > > encrypts as follows: 5BAA61E4C9B93F3F68225B6CF8331B7EE68FD8
    > > >
    > > > If I run the web based version with the word password I get the
    > following:
    > > > 5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8
    > > >
    > > > Notice the web version has extra in it.
    > > > Please help..... Below is the code I have been using for both
    versions:
    > > >
    > > > Web Version:
    > > > Dim PwdAs String = "password"
    > > > Dim hashedPwd As String =
    > > > FormsAuthentication.HashPasswordForStoringInConfig File(Pwd, "SHA1")
    > > > Return hashedPwd
    > > >
    > > >
    > > > Windows Exe Version:
    > > > Dim PwdAs String = Trim("password")
    > > > Dim Data As Byte()
    > > > Data = System.Text.Encoding.ASCII.GetBytes(Pwd)
    > > > Dim shaM As New SHA1Managed
    > > > Dim resultHash As Byte() = shaM.ComputeHash(Data)
    > > > Dim hashedpwd = ""
    > > > Dim b As Byte
    > > > For Each b In resultHash
    > > > hashedpwd += Hex(b)
    > > > Next
    > > > Return hashedpwd
    > > >
    > > >
    > > > Thanks
    > > > Jamie
    > > >
    > > >
    > >
    > >
    >
    >

    Joe Kaplan \(MVP - ADSI\) Guest

  6. #5

    Default Re: Please Help - Encryption Problems

    Thanks Guys,
    You have been so much help. FYI. I am using salt but i though to remove the
    code save space etc....Have any of you people had any experiance of writting
    a VLE (virtual Learning Enviroment) (teaching Online) if so what could thing
    could you recommend?

    Again Many Thanks, I will try on Monday.


    Jamie


    "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com> wrote
    in message news:Ow%23D0HWKEHA.3704@TK2MSFTNGP11.phx.gbl...
    > I also agree with Hernan in that adding random salt is very important to
    > prevent dictionary attacks. There have been some excellent articles
    written
    > on this topic recently.
    >
    > Joe K.
    >
    > "Hernan de Lahitte" <hernan@lagash.com> wrote in message
    > news:%23cXrhBVKEHA.3704@TK2MSFTNGP11.phx.gbl...
    > > I agree with Joe suggestion.
    > > FormsAuthentication.HashPasswordForStoringInConfig File method actually
    > > encode in UTF8 and not in ASCII as you do in the WinForms scenario. BTW,
    I
    > > suggest to use the same methods for both clients
    > > (HashPasswordForStoringInConfigFile should be well suited in this case).
    > > However, if you are hashing passwords for storing in a DB, I recommend
    you
    > > to add a salt value for dictionary attacks mitigation. Check out this
    code
    > > from
    > >
    >
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetch12.asp:[/url]
    > >
    > > Creating a Salt Value
    > > The following code shows how to generate a salt value by using random
    > number
    > > generation functionality provided by the RNGCryptoServiceProvider class
    > > within the System.Security.Cryptography namespace.
    > >
    > > public static string CreateSalt(int size)
    > > {
    > > RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
    > > byte[] buff = new byte[size];
    > > rng.GetBytes(buff);
    > > return Convert.ToBase64String(buff);
    > > }Creating a Hash Value (with Salt)
    > > The following code fragment shows how to generate a hash value from a
    > > supplied password and salt value.
    > >
    > > public static string CreatePasswordHash(string pwd, string salt)
    > > {
    > > string saltAndPwd = string.Concat(pwd, salt);
    > > string hashedPwd =
    > > FormsAuthentication.HashPasswordForStoringInConfig File(
    > > saltAndPwd, "SHA1");
    > > return hashedPwd;
    > > }
    > >
    > >
    > > --
    > > Hernan de Lahitte
    > > Lagash Systems S.A.
    > > [url]http://weblogs.asp.net/hernandl[/url]
    > >
    > >
    > > This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    > >
    > > "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com>
    wrote
    > > in message news:%23jvEnWUKEHA.3924@tk2msftngp13.phx.gbl...
    > > > It is probably an encoding problem. Forms auth uses UTF8 encoding and
    > you
    > > > are using ASCII. I suggest you try switching to UTF8 first.
    > > >
    > > > Joe K.
    > > >
    > > > "Jamie Sutherland" <jamie.sutherland@nhcscotland.no.spam.com> wrote in
    > > > message news:eH30GnTKEHA.3380@TK2MSFTNGP09.phx.gbl...
    > > > > Hi,
    > > > > I have a problem in that I have 2 applications writing to the same
    > > > Database.
    > > > > One App is web based and the other is windows/forms based.
    > > > > Both have the same job in that they can reset a users password in
    the
    > > > > database. Both are using SHA1 encryption however they both ghive
    > > different
    > > > > results when the programs are run.
    > > > > If I run the windows exe file and set the password to password the
    exe
    > > > > encrypts as follows: 5BAA61E4C9B93F3F68225B6CF8331B7EE68FD8
    > > > >
    > > > > If I run the web based version with the word password I get the
    > > following:
    > > > > 5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8
    > > > >
    > > > > Notice the web version has extra in it.
    > > > > Please help..... Below is the code I have been using for both
    > versions:
    > > > >
    > > > > Web Version:
    > > > > Dim PwdAs String = "password"
    > > > > Dim hashedPwd As String =
    > > > > FormsAuthentication.HashPasswordForStoringInConfig File(Pwd, "SHA1")
    > > > > Return hashedPwd
    > > > >
    > > > >
    > > > > Windows Exe Version:
    > > > > Dim PwdAs String = Trim("password")
    > > > > Dim Data As Byte()
    > > > > Data = System.Text.Encoding.ASCII.GetBytes(Pwd)
    > > > > Dim shaM As New SHA1Managed
    > > > > Dim resultHash As Byte() = shaM.ComputeHash(Data)
    > > > > Dim hashedpwd = ""
    > > > > Dim b As Byte
    > > > > For Each b In resultHash
    > > > > hashedpwd += Hex(b)
    > > > > Next
    > > > > Return hashedpwd
    > > > >
    > > > >
    > > > > Thanks
    > > > > Jamie
    > > > >
    > > > >
    > > >
    > > >
    > >
    > >
    >
    >

    Jamie Sutherland Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139