Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6153283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:04:10+00:00 2026-05-23T20:04:10+00:00

using BouncyCastle and with help from a stackoverflow question I got this: using System.Net.Sockets;

  • 0

using BouncyCastle and with help from a stackoverflow question I got this:

        using System.Net.Sockets;
        using System.Security.Cryptography;
        using Org.BouncyCastle.Crypto.Parameters;
        using Org.BouncyCastle.OpenSsl;

…

        TcpClient client = new TcpClient("127.0.0.1", 1337);
        NetworkStream stream = client.GetStream();

        StreamWriter writer= new StreamWriter(stream);
        StreamReader reader = new StreamReader(stream);

        writer.WriteLine("hello");
        writer.AutoFlush = true;

        string response = Convert.FromBase64String(reader.ReadToEnd()).ToString();

        RSACryptoServiceProvider RCP;
        var x = new PemReader(File.OpenText(pubkey));
        var y = (RsaKeyParameters)x.ReadObject();

        RCP = (RSACryptoServiceProvider)RSACryptoServiceProvider.Create();

        var pa = new RSAParameters();
        pa.Modulus = y.Modulus.ToByteArray();
        pa.Exponent = y.Exponent.ToByteArray();

        RCP.ImportParameters(pa);
        byte[] test = RCP.Decrypt(response, true);

Now, obviously Decrypt will fail, as since I’m trying to decrypt something which was signed (not “encrypted”) and definately not by the same “key”. I’m confused since I thought I should use a method like VerifyData(), but this returns a bool and takes arguments I’m not sure I have.

What I wish to accomplish is the C# equivalent of openssl rsautl -verify -inkey public.pem -pubin. That is, “decrypt” with the pubkey to verify the contents of said message.

Am I on the right track here?

  • Mik
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:04:11+00:00Added an answer on May 23, 2026 at 8:04 pm

    Actually a decrypt of a signature should never fail unless you specified the wrong encoding parameters – a signature is simply the private-key encrypted hash of the data (typically SHA1); the only benefit of using the verify routine is that it decrypts the block and does the hash comparison work for you, if you wanted to be bloody minded you could instead do a decrypt operation with your public key and compare the hash bytes yourself.

    I’m not actually sure what response is in the context of your program; you should only be passing the RSA data to it, if you’re also feeding it the data that was signed in the first place you are doing it wrong – similarly, do check if that function actually accepts a string, in my experience BouncyCastle generally expects a byte[]

    I’d recommend using SignerUtilities.GetSigner() – it takes a string arg to tell it what sort of signature you’re using, I would imagine "SHA1WithRSA" to be right for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a small application using bouncycastle algorithm, from the BouncyCastleProvider.java
Using online interfaces to a version control system is a nice way to have
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
Using VS2008, C#, .Net 2 and Winforms how can I make a regular Button
Using preview 4 of ASP.NET MVC Code like: <%= Html.CheckBox( myCheckBox, Click Here, True,
Need some help with crypto routines in Java. Given a PKCS#7 signature, I want
I'm trying to digitally sign a PDF file using THIS project as an example.
I am trying to sign a token object using SHA1. I am using bouncycastle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.