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. Signing Data using RSA

Signing Data using RSA

Scheduled Pinned Locked Moved C#
helptutorialdockeralgorithmsxml
3 Posts 2 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.
  • N Offline
    N Offline
    nyjcr
    wrote on last edited by
    #1

    Hello, I'm having difficulty signing a string using the RSA cryptography algorithm. I've search here in this forum for sample code, but I guess, signing is not that popular. Anyway, any help would be greatly appreciated. here is my code.

    public static string SignMyData(string data2Sign)
    {
    AssignPr(); //assigning the parameter, container, etc

    byte[] byte2Sign = System.Text.Encoding.UTF8.GetBytes(data2Sign);

    StreamReader reader = new StreamReader(@"C:\MyPrivateKey.xml");
    string pubPriKeyXML = reader.ReadToEnd();
    rsa.FromXmlString(pubPriKeyXML); //(I'm getting error "Invalid syntax on line 1".)
    reader.Close();

    byte[] byteSig = rsa.SignData(byte2Sign, "SHA1");
    return System.Text.Encoding.UTF8.GetString(ByteSig);
    }

    If anyone knows of a simple tutorial or can guide me through this, that would be great Thanks JC

    E 2 Replies Last reply
    0
    • N nyjcr

      Hello, I'm having difficulty signing a string using the RSA cryptography algorithm. I've search here in this forum for sample code, but I guess, signing is not that popular. Anyway, any help would be greatly appreciated. here is my code.

      public static string SignMyData(string data2Sign)
      {
      AssignPr(); //assigning the parameter, container, etc

      byte[] byte2Sign = System.Text.Encoding.UTF8.GetBytes(data2Sign);

      StreamReader reader = new StreamReader(@"C:\MyPrivateKey.xml");
      string pubPriKeyXML = reader.ReadToEnd();
      rsa.FromXmlString(pubPriKeyXML); //(I'm getting error "Invalid syntax on line 1".)
      reader.Close();

      byte[] byteSig = rsa.SignData(byte2Sign, "SHA1");
      return System.Text.Encoding.UTF8.GetString(ByteSig);
      }

      If anyone knows of a simple tutorial or can guide me through this, that would be great Thanks JC

      E Offline
      E Offline
      Elroy Dsilva
      wrote on last edited by
      #2

      nyjcr wrote:

      rsa.FromXmlString(pubPriKeyXML);

      'rsa' seems to be a non-static member variable. You cannot use non-static member variables in static methods. Try changing your method to a non-static one.

      1 Reply Last reply
      0
      • N nyjcr

        Hello, I'm having difficulty signing a string using the RSA cryptography algorithm. I've search here in this forum for sample code, but I guess, signing is not that popular. Anyway, any help would be greatly appreciated. here is my code.

        public static string SignMyData(string data2Sign)
        {
        AssignPr(); //assigning the parameter, container, etc

        byte[] byte2Sign = System.Text.Encoding.UTF8.GetBytes(data2Sign);

        StreamReader reader = new StreamReader(@"C:\MyPrivateKey.xml");
        string pubPriKeyXML = reader.ReadToEnd();
        rsa.FromXmlString(pubPriKeyXML); //(I'm getting error "Invalid syntax on line 1".)
        reader.Close();

        byte[] byteSig = rsa.SignData(byte2Sign, "SHA1");
        return System.Text.Encoding.UTF8.GetString(ByteSig);
        }

        If anyone knows of a simple tutorial or can guide me through this, that would be great Thanks JC

        E Offline
        E Offline
        Elroy Dsilva
        wrote on last edited by
        #3

        nyjcr wrote:

        If anyone knows of a simple tutorial or can guide me through this, that would be great

        http://blogs.msdn.com/nicold/archive/2007/09/03/how-to-digitally-sign-a-string.aspx[^]

        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