-2

I am trying to convert some java source code to C#.

What is the equivalent of the following Java classes in c#:

Thank you

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
koko
  • 1
  • 2

1 Answers1

1

I am not 100% sure but it might be the following.

  1. RSACryptoServiceProvider

https://blogs.msdn.microsoft.com/shawnfa/2008/08/25/using-rsacryptoserviceprovider-for-rsa-sha256-signatures/ for RsaSHA256Signer

So code will look like that :

    byte[] data = new byte[] { 0, 1, 2, 3, 4, 5 };
    using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
    {
        byte[] signature = rsa.SignData(data, "SHA256");
        if (rsa.VerifyData(data, "SHA256", signature))
        {
              Console.WriteLine("RSA-SHA256 signature verified");
        }
         else
        {
            Console.WriteLine("RSA-SHA256 signature failed to verify");
        }
    }
  1. The equivalent package to java.time will be System.DateTime

For example:

Java:

Instant instant = Instant.now();

C#:

DateTime localDate = DateTime.UtcNow;

https://learn.microsoft.com/en-us/dotnet/api/system.datetime.now?view=netframework-4.8

Additionally, you can look for Noda Time which is a popular library.

Sergii Zhuravskyi
  • 4,006
  • 5
  • 18
  • 26
  • I would suggest changing `DateTime.Now` to `DateTime.UtcNow`, given that `Instant.now()` isn't affected by the system-local time zone, but `DateTime.Now` is. – Jon Skeet Oct 09 '19 at 16:16
  • Yes, you are correct. Your suggestion is a better fit. Updated my answer accordingly. – Sergii Zhuravskyi Oct 09 '19 at 16:46