Avatar of SkipFire
SkipFire
 asked on

Decrypt SHA1-RSA

I need to be able to decrypt a string that is encrypted with a certificate using SHA1-RSA.  This is being used to integrate a .NET application with authentication from an existing system that cannot be changed.

Please provide sample code, or a link to a sample project.  C# or VB.NET code is fine and I would prefer code that is compatible with both .NET 1.1 and .NET 2.0.  I would like to avoid third-party components as the procurement process for this client is rather slow and painful.

If it helps, the following Java code encrypted what I need to decrypt.

public String createUrlFragment(String privateKeyName, String privateKeyPassword, String authString) throws UrlAuthenticationException
{
    try
    {
      PrivateKey privateKey = (PrivateKey) _keyStore.getKey(privateKeyName, privateKeyPassword.toCharArray());
      Enumeration e = _keyStore.aliases();
      while(e.hasMoreElements())
      {
              System.out.println("alais:" + (String)e.nextElement());
      }
      if (privateKey == null)
                 throw new UrlAuthenticationException("No key " + privateKeyName + " found");
      Signature signature = Signature.getInstance("SHA1withRSA");
      signature.initSign(privateKey);
      signature.update(authString.getBytes());
      byte[] sig1 = signature.sign();
      String base64 =Base64.encodeBytes(sig1);
      String urlFragment = "user=" + URLEncoder.encode(authString,"UTF-8") + "&authSignature=" + URLEncoder.encode(base64,"UTF-8");
      return urlFragment;
    }
    catch (Exception e)
    {
      throw new UrlAuthenticationException("UrlAuthenticationException: " + e.toString());
    }
  }
}  

.NET Programming

Avatar of undefined
Last Comment
SkipFire

8/22/2022 - Mon
joechina

SkipFire

ASKER
That article is not helping with my current dilemma, any other suggestions?  When trying to decrypt I am basically trying to make sure I do the steps backwards from the Java code, but the string that I am inputting is not a multiple of 4 so it fails when trying to feed it in as a base64 string.
joechina

Hi,SkipFire
if the input is not a multiple of 4, could you pad it with space or -?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
SkipFire

ASKER
Tried padding it front and back with everything I could think of.
joechina

back
joechina

sry, give me a couple day. I will try here. thx
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
joechina

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SkipFire

ASKER
Thanks.  As soon as I find out what the keypassword is, and what format the key is, I will try it out and let you know if it works.  Hopefully that will be today or tomorrow.
joechina

the keypassword parameter for your java function is the password you put when you export your PKCS12 file.
SkipFire

ASKER
I know, I don't have access to the full java code, just the snippit that I posted here.  
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
SkipFire

ASKER
I'm going to assume that this will work, I have no clue when I will get the password.