Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How Can I Hide String Key

How Can I Hide String Key

Scheduled Pinned Locked Moved C#
questiondotnetsecurity
17 Posts 7 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D dataminers

    My dll file contains private key value. I used this key for encryption. How can I hide this key. If I use Reflector or other tool so show my code. I think obfuscation or post-build not guarantee hide my key value. I use strong key but, it can be remove using with Reflector plug-in. I add dll to GAC but, it easly to steal (Start --> Run ---> C:\windows\assembly\gac_msil). Do you have any idea? Best Regards...

    realJSOPR Offline
    realJSOPR Offline
    realJSOP
    wrote on last edited by
    #4

    A decent obfuscation tool (NOT the one that comes with Visual Studio) will encrypt strings so reflector doesn't show anything useful.

    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
    -----
    "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

    D 1 Reply Last reply
    0
    • realJSOPR realJSOP

      A decent obfuscation tool (NOT the one that comes with Visual Studio) will encrypt strings so reflector doesn't show anything useful.

      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
      -----
      "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

      D Offline
      D Offline
      dataminers
      wrote on last edited by
      #5

      Which one is better; Dotfuscator Professional (preemptive) Salamander .NET obfuscator (remotesoft) And what is your think about post-build? Do you use Xenocode Postbuild? Best Regards...

      1 Reply Last reply
      0
      • M musefan

        hmmm. not quite sure. but i have just thought of something (maybe a little crazy but hey) What about writting a small hardcoded algorithm that rearanges the key before using it for decryption/encryption? that way the stored 'key string' cannot be directly used by anybody else. unless of course they can get hold of your hardcoded algorithm. but that is harder than just getting the string, is it not? instead of your own algorithm, maybe you could just use a hash value of the original key What you think?

        Life goes very fast. Tomorrow, today is already yesterday.

        D Offline
        D Offline
        dataminers
        wrote on last edited by
        #6

        Dear Musefan; First of all thanks for care. I have a algorithm like blowfish. I already written hardcoded this algorithm. But most important of this algorithmts need a key. This enuqe key is most important for this algorithm and it will be hide. Thanks...

        1 Reply Last reply
        0
        • 0 0x3c0

          One thing Reflector doesn't show (AFAIK) is class-level fields. Since Reflector treats a const like a field, just put your key in a class-level static const. It can still be retrieved using custom-tailored reflection code, but it should deter casual hackers. I've done this in a private application, which uses a 256-length byte array to encrypt passwords; I couldn't retrieve the value using Reflector

          D Offline
          D Offline
          dataminers
          wrote on last edited by
          #7

          Which program did you use for ? How can I put my key in a class-level static const. Dotfuscator Community Edition is not convert variables. Best Regards...

          0 1 Reply Last reply
          0
          • D dataminers

            Which program did you use for ? How can I put my key in a class-level static const. Dotfuscator Community Edition is not convert variables. Best Regards...

            0 Offline
            0 Offline
            0x3c0
            wrote on last edited by
            #8

            I didn't. However, on further analysis it turns out that the value is set from the static constructor of the class. Although it puts off casual crackers, it will not dissuade those who are determined to get the value. By class-level static const, I mean something like this:

            internal class Program
            {
            internal static const string mySecretPassword = "Lorem";
            }

            However, it cannot compensate for a good obfuscation system and cannot stand on its own

            modified on Wednesday, March 11, 2009 12:42 PM

            D 1 Reply Last reply
            0
            • D dataminers

              My dll file contains private key value. I used this key for encryption. How can I hide this key. If I use Reflector or other tool so show my code. I think obfuscation or post-build not guarantee hide my key value. I use strong key but, it can be remove using with Reflector plug-in. I add dll to GAC but, it easly to steal (Start --> Run ---> C:\windows\assembly\gac_msil). Do you have any idea? Best Regards...

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #9

              You're planning to combine relatively insecure ways to hide a key with a very strong encryption algorithm? That strikes me as odd - it's a bit like having 10 locks on your door but putting the key under the doormat.

              C M D 3 Replies Last reply
              0
              • L Lost User

                You're planning to combine relatively insecure ways to hide a key with a very strong encryption algorithm? That strikes me as odd - it's a bit like having 10 locks on your door but putting the key under the doormat.

                C Offline
                C Offline
                Curtis Schlak
                wrote on last edited by
                #10

                I second this comment!

                "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

                1 Reply Last reply
                0
                • L Lost User

                  You're planning to combine relatively insecure ways to hide a key with a very strong encryption algorithm? That strikes me as odd - it's a bit like having 10 locks on your door but putting the key under the doormat.

                  M Offline
                  M Offline
                  Mark Churchill
                  wrote on last edited by
                  #11

                  Good call. If you were using crypto appropriately, then you wouldnt need to hide the key that the user is going to use. Alice can't send a secret message to Bob and then have Bob read it sometimes, but not other times. Maths doesnt work that way...

                  Mark Churchill Director, Dunn & Churchill Pty Ltd Free Download: Diamond Binding: The simple, powerful, reliable, and effective data layer toolkit for Visual Studio.
                  Entanglar: .Net game engine featuring automatic networking and powerful HLSL gfx binding.

                  1 Reply Last reply
                  0
                  • 0 0x3c0

                    I didn't. However, on further analysis it turns out that the value is set from the static constructor of the class. Although it puts off casual crackers, it will not dissuade those who are determined to get the value. By class-level static const, I mean something like this:

                    internal class Program
                    {
                    internal static const string mySecretPassword = "Lorem";
                    }

                    However, it cannot compensate for a good obfuscation system and cannot stand on its own

                    modified on Wednesday, March 11, 2009 12:42 PM

                    D Offline
                    D Offline
                    dataminers
                    wrote on last edited by
                    #12

                    In your sample not include identifier (for example string), so compiler get error. I try this; internal class MyClass { internal static readonly string mySecretPassword1 = "MySecretKey"; private static readonly string mySecretPassword2 = "MySecretKey"; private const string mySecretPassword3 = "MySecretKey"; internal const string mySecretPassword4 = "MySecretKey"; private static string mySecretPassword5 = "MySecretKey"; internal static string mySecretPassword6 = "MySecretKey"; } And obfuscation with Dotfuscator Community Edition and Salamander .NET obfuscator. And post build with Xenocode Postbuild 2008 for .NET. But I can see "MySecretKey" when I open obfuscated dll with reflector. In ".cctor()" function. Note: In C#.NET const = value assigned at Compile time and unchangeable once established. readonly = value assigned at run time and unchangeable once established.

                    0 1 Reply Last reply
                    0
                    • L Lost User

                      You're planning to combine relatively insecure ways to hide a key with a very strong encryption algorithm? That strikes me as odd - it's a bit like having 10 locks on your door but putting the key under the doormat.

                      D Offline
                      D Offline
                      dataminers
                      wrote on last edited by
                      #13

                      Ok. How can I Blowfish, Twofish or AES algorithims in ASP.NET project. All of them needs private key.

                      L 1 Reply Last reply
                      0
                      • D dataminers

                        Ok. How can I Blowfish, Twofish or AES algorithims in ASP.NET project. All of them needs private key.

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #14

                        You can use them, but you should only use them to encrypt a communication channel. Anything else is not "encryptable" - you may try but it still won't be safe, no matter what.

                        D 1 Reply Last reply
                        0
                        • L Lost User

                          You can use them, but you should only use them to encrypt a communication channel. Anything else is not "encryptable" - you may try but it still won't be safe, no matter what.

                          D Offline
                          D Offline
                          dataminers
                          wrote on last edited by
                          #15

                          Could you explain "encrypt a communication channel"? Is it means SSL certificiate installed and configured server?

                          L 1 Reply Last reply
                          0
                          • D dataminers

                            Could you explain "encrypt a communication channel"? Is it means SSL certificiate installed and configured server?

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #16

                            Actually it's more like a fundamental theory in crypto. Yes SSL "works", because it encrypts traffic between two computers, and that's a communication channel. Encrypting a communication channel just means that there are 2 parties involved and they can talk to each other, but anyone else who happens to be listening only receives a garbled mess. Encryption of data only works if the key is guaranteed not to fall into the wrong hands. This guarantee is what makes it impossible, because it means you can't tell to key to anyone, including the program that you want to decrypt the data. This is why passwords don't "work" - they can be stolen (key loggers, fake websites, phishing emails etc). If "the wrong hands" includes the person using the program, obviously the program should not have the key, because no matter what trickery you use the key will at some point be available to the program and thus also to the person operating the computer. So what I hope, is that you only want to keep the data a secret from "others" - for example other people on the network (LAN/WAN whatever) who could overhear the communication between your site (it's a site right?) and a user. SSL does this, but you could use other algorithms as well (if the client allows it, if it's a program you control you could use anything you want). If the algorithm you want to use is not a public key algorithm you could use something like the Diffie-Hellman exchange to effectively turn it into a public key algorithm. ps: please do not sue me if you find any errors in what I just said :)

                            1 Reply Last reply
                            0
                            • D dataminers

                              In your sample not include identifier (for example string), so compiler get error. I try this; internal class MyClass { internal static readonly string mySecretPassword1 = "MySecretKey"; private static readonly string mySecretPassword2 = "MySecretKey"; private const string mySecretPassword3 = "MySecretKey"; internal const string mySecretPassword4 = "MySecretKey"; private static string mySecretPassword5 = "MySecretKey"; internal static string mySecretPassword6 = "MySecretKey"; } And obfuscation with Dotfuscator Community Edition and Salamander .NET obfuscator. And post build with Xenocode Postbuild 2008 for .NET. But I can see "MySecretKey" when I open obfuscated dll with reflector. In ".cctor()" function. Note: In C#.NET const = value assigned at Compile time and unchangeable once established. readonly = value assigned at run time and unchangeable once established.

                              0 Offline
                              0 Offline
                              0x3c0
                              wrote on last edited by
                              #17

                              Whoops; I've added string to the code sample. As I said, all that my method does is hide it from a cursory look. It cannot compensate for a dedicated obfuscation package. I have chosen the const keyword because it simply provides safety in case I ever go past the ballmer peak and change its value; my choice was quite deliberate

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups