troubleshooting Question

Decrypt SHA1-RSA

Avatar of SkipFire
SkipFire asked on
.NET Programming
11 Comments1 Solution23416 ViewsLast Modified:
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());
    }
  }
}  

ASKER CERTIFIED SOLUTION
joechina

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros