Hash and sign a message with RSA algo in c# for compact framework -


hy everybody,

i try sign 1 message rsa algorithm, i'm working compact framwork code:

private void signer_click(object sender, eventargs e) {     ///cle de string ver byte[]     string clepriveefile = @"\program files\privatekey.pem";      streamreader reader = new streamreader(clepriveefile);     string contenukeyprivate = reader.readtoend();     byte[] keybyte = certification.decodeopensslprivatekey(contenukeyprivate);      string data = "salut tout le monde";      byte[] databytes = system.text.encoding.utf8.getbytes(data);//.utf7.getbytes(data);      //hasher le message     sha1managed sha1 = new sha1managed();     byte[] hash = sha1.computehash(databytes);      string hach = convert.tobase64string(hash);        rsacryptoserviceprovider rsa = certification.decodersaprivatekey(keybyte);      byte[] sign = rsa.signhash(hash, cryptoconfig.mapnametooid("sha1"));      string resultat = convert.tobase64string(sign);      this.label1.text = this.resultat;  } 

with 'decodeopensslprivatekey' , 'decodersaprivatekey' it's sames functions use here: http://www.jensign.com/opensslkey/index.html

for result of hash obtain: hash = "i4t474lio6h+p8sedsoikxmi8b0="

if same things openssl command: $ echo "salut tout le monde"| openssl dgst -sha1 | openssl enc -base64

i obtain this: "njflowi4y2njn2u2mzfkntqwntrmzje1zguyyzk2mdczytm2zjrjzao="

same sign result, command:

$ echo "salut tout le monde"| openssl dgst -sha1 -sign privatekey.pem | openssl enc -base64

i have signature this: "v6c6xnk7o8+ikkugtgendzwowxhqliefhw7xsdoxzmap1glu8b5uxxi0lr6jhvdw6si8p8ptlt+fxeoafy+zcigiq4xw6e32f6hxyweyi7silh44i1m7lf7jyr1lfcegno0cw+ypqlprrzubdcrvmo1ijugh3suk+iot2lait9s="

with code obtain this:

result = "ylbnppfdp5ejdyopoui/1w6i+clrkrxbida24iqllgdrwgbrwltgwlfnkh4+b+gzcrx8hi7pknp1pq2ud1je4ehfuvjbkzjwxj/zyi3fpf41oiimdf63lzir/sehq5rmtbdsfqtkkbmftr8udcjnnmnsimrq458nzvisyouw6j4="

i can't find error :( can me?

one problem echo output contains newline suffix. try hashing "salut tout le monde\n". openssl outputs sha1 digest in hex-encoded format, encoding result in base64 meaningless.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -