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. Cryptography

Cryptography

Scheduled Pinned Locked Moved C#
cryptographytutorialquestionworkspace
6 Posts 3 Posters 0 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.
  • Y Offline
    Y Offline
    Yaakov Davis
    wrote on last edited by
    #1

    Hi all. I want to generate a hashcode from string and encrypt it with the private key of a .sn file (strong name key pair). The purpose is to hash the contents of a configuration file, encrypt it, and add the encrypted hash to the file. At runtime, I want to decrypt the hash with the public key of the assembly, and determine whether the hash is the same of the current hash of the contents. I have no idea how to do that in practical, can you give some guidelines for that? Any references would be welcome. Thanks a lot, Yaakov

    T Y E 3 Replies Last reply
    0
    • Y Yaakov Davis

      Hi all. I want to generate a hashcode from string and encrypt it with the private key of a .sn file (strong name key pair). The purpose is to hash the contents of a configuration file, encrypt it, and add the encrypted hash to the file. At runtime, I want to decrypt the hash with the public key of the assembly, and determine whether the hash is the same of the current hash of the contents. I have no idea how to do that in practical, can you give some guidelines for that? Any references would be welcome. Thanks a lot, Yaakov

      T Offline
      T Offline
      Trance Junkie
      wrote on last edited by
      #2

      hmm.... I will look in to it man !:laugh:

      1 Reply Last reply
      0
      • Y Yaakov Davis

        Hi all. I want to generate a hashcode from string and encrypt it with the private key of a .sn file (strong name key pair). The purpose is to hash the contents of a configuration file, encrypt it, and add the encrypted hash to the file. At runtime, I want to decrypt the hash with the public key of the assembly, and determine whether the hash is the same of the current hash of the contents. I have no idea how to do that in practical, can you give some guidelines for that? Any references would be welcome. Thanks a lot, Yaakov

        Y Offline
        Y Offline
        Yaakov Davis
        wrote on last edited by
        #3

        I found a helper class that answers most of my questions. Here: http://spaces.msn.com/members/staceyw/Blog/cns!1pnsZpX0fPvDxLKC6rAAhLsQ!284.entry?beid=cns!1pnsZpX0fPvDxLKC6rAAhLsQ!284#postcns!1pnsZpX0fPvDxLKC6rAAhLsQ!284[^]

        1 Reply Last reply
        0
        • Y Yaakov Davis

          Hi all. I want to generate a hashcode from string and encrypt it with the private key of a .sn file (strong name key pair). The purpose is to hash the contents of a configuration file, encrypt it, and add the encrypted hash to the file. At runtime, I want to decrypt the hash with the public key of the assembly, and determine whether the hash is the same of the current hash of the contents. I have no idea how to do that in practical, can you give some guidelines for that? Any references would be welcome. Thanks a lot, Yaakov

          E Offline
          E Offline
          Enishi
          wrote on last edited by
          #4

          Hi, i used this code i hope it helps u and u understand it RSACryptoServiceProvider RSA; RSA = new RSACryptoServiceProvider(); byte[] rawData, hash; HashAlgorithm HashMan; HashMan = new SHA1CryptoServiceProvider(); rawData= System.Text.Encoding.Unicode.GetBytes(string PASSWORD); ///get the bytes of the original password hash = HashMan.ComputeHash(rawData); //uses the private key to generate the hash RSAPKCS1SignatureFormatter sf = new RSAPKCS1SignatureFormatter(RSA); //this one will use the public key to encode it more sf.SetHashAlgorithm("SHA1"); byte []FinalSignature= sf.CreateSignature(hash); //creates the signature, u will send this one to the receiver along with the public key RSA.ExportParameters(false); //this both sentences will give the public key, if u pass them true will give also the private key. RSA.ToXMLString(false); ull send to the receiver the FinalSignature and the RSAParameters or the string with the public key. in the receiver //if u used the RSA.EXPORTPARAMETERS RSAPKCS1SignatureDeformatter sd=new RSAPKCS1SignatureDeformatter(parameters); // or if u used the xml string RSAPKCS1SignatureDeformatter sd=new RSAPKCS1SignatureDeformatter(); sd.FromXMLString(string xmlParameters); // sd.SetHashAlgorithm("SHA1"); bool pd=sd.VerifySignature(hashinurdatabase,FinalSignature); i hope it helps u with the code if u dont uderstand something or want to ask something just say here or emailme. U will need to give to the SignatureDefformater the parameters of the RSACryptoServerProvider u used in the SignatuerDefformater or it will return u false.

          Y 1 Reply Last reply
          0
          • E Enishi

            Hi, i used this code i hope it helps u and u understand it RSACryptoServiceProvider RSA; RSA = new RSACryptoServiceProvider(); byte[] rawData, hash; HashAlgorithm HashMan; HashMan = new SHA1CryptoServiceProvider(); rawData= System.Text.Encoding.Unicode.GetBytes(string PASSWORD); ///get the bytes of the original password hash = HashMan.ComputeHash(rawData); //uses the private key to generate the hash RSAPKCS1SignatureFormatter sf = new RSAPKCS1SignatureFormatter(RSA); //this one will use the public key to encode it more sf.SetHashAlgorithm("SHA1"); byte []FinalSignature= sf.CreateSignature(hash); //creates the signature, u will send this one to the receiver along with the public key RSA.ExportParameters(false); //this both sentences will give the public key, if u pass them true will give also the private key. RSA.ToXMLString(false); ull send to the receiver the FinalSignature and the RSAParameters or the string with the public key. in the receiver //if u used the RSA.EXPORTPARAMETERS RSAPKCS1SignatureDeformatter sd=new RSAPKCS1SignatureDeformatter(parameters); // or if u used the xml string RSAPKCS1SignatureDeformatter sd=new RSAPKCS1SignatureDeformatter(); sd.FromXMLString(string xmlParameters); // sd.SetHashAlgorithm("SHA1"); bool pd=sd.VerifySignature(hashinurdatabase,FinalSignature); i hope it helps u with the code if u dont uderstand something or want to ask something just say here or emailme. U will need to give to the SignatureDefformater the parameters of the RSACryptoServerProvider u used in the SignatuerDefformater or it will return u false.

            Y Offline
            Y Offline
            Yaakov Davis
            wrote on last edited by
            #5

            Thanks for the detailed answer. If I get it right, I can replace the following code: HashAlgorithm HashMan; HashMan = new SHA1CryptoServiceProvider(); rawData= System.Text.Encoding.Unicode.GetBytes(string PASSWORD); hash = HashMan.ComputeHash(rawData); RSAPKCS1SignatureFormatter sf = new RSAPKCS1SignatureFormatter(RSA); sf.SetHashAlgorithm("SHA1"); byte[] FinalSignature= sf.CreateSignature(hash); with this one: rawData = System.Text.Encoding.Unicode.GetBytes(string PASSWORD); byte[] FinalSignature = RSA.SignData(rawData, "SHA1"); Is that correct? Yaakov

            E 1 Reply Last reply
            0
            • Y Yaakov Davis

              Thanks for the detailed answer. If I get it right, I can replace the following code: HashAlgorithm HashMan; HashMan = new SHA1CryptoServiceProvider(); rawData= System.Text.Encoding.Unicode.GetBytes(string PASSWORD); hash = HashMan.ComputeHash(rawData); RSAPKCS1SignatureFormatter sf = new RSAPKCS1SignatureFormatter(RSA); sf.SetHashAlgorithm("SHA1"); byte[] FinalSignature= sf.CreateSignature(hash); with this one: rawData = System.Text.Encoding.Unicode.GetBytes(string PASSWORD); byte[] FinalSignature = RSA.SignData(rawData, "SHA1"); Is that correct? Yaakov

              E Offline
              E Offline
              Enishi
              wrote on last edited by
              #6

              i am not sure, i think i tried that way but it didnt work for me, i needed to sign the data from the hash with the signature formatter cause it will encode it too. Try if u can do it that way, but i think the sign data didnt do the same as the signatureformatter

              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