Cryptography
-
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
-
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
hmm.... I will look in to it man !:laugh:
-
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
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[^]
-
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
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. -
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.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 -
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? Yaakovi 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