signing - Need to sign a string with RSASSA-PKCS1-v1_5 signature in c# -


i have string message , private key. need write c# code can sign string rsassa-pkcs1-v1_5 signature.

do have hints or suggestions should start looking accomplish this? there existing apis in .net or in available libraries this?

this example how it, can implement needed changes in code (the example msdn site:

using system; using system.security.cryptography; using org.bouncycastle.openssl; using org.bouncycastle.crypto; using org.bouncycastle.security; using org.bouncycastle.crypto.parameters;  class rsasample {    const string pubkeyfile = @"c:\encrypt\filewithkey.pem";         const string keyname = "key01";         cspparameters cspp = new cspparameters();         rsaparameters rsakeyinfo = new rsaparameters();          org.bouncycastle.utilities.io.pem.pemobject po = null;         using (streamreader sr = new streamreader(pubkeyfile))         {             org.bouncycastle.openssl.pemreader pr = new org.bouncycastle.openssl.pemreader(reader);             po = pr.readpemobject();         }          rsakeyinfo.modulus = po.content;         cspp.keycontainername = keyname;          try          {              //create new instance of rsacryptoserviceprovider.               using (rsacryptoserviceprovider rsa = new rsacryptoserviceprovider(cspp))              {                  rsa.persistkeyincsp = true;                  rsa.importparameters(rsakeyinfo);                  //the hash sign.                   byte[] hash;                  using (sha256 sha256 = sha256.create())                  {                      byte[] data = new byte[] { 59, 4, 248, 102, 77, 97, 142, 201, 210, 12, 224, 93, 25, 41, 100, 197, 213, 134, 130, 135 };                      hash = sha256.computehash(data);                  }                    //create rsasignatureformatter object , pass                    //rsacryptoserviceprovider transfer key information.                  rsapkcs1signatureformatter rsaformatter = new rsapkcs1signatureformatter(rsa);                   //set hash algorithm sha256.                  rsaformatter.sethashalgorithm("sha256");                   //create signature hashvalue , return it.                   byte[] signedhash = rsaformatter.createsignature(hash);              }           }          catch (cryptographicexception e)          {              console.writeline(e.message);          } } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -