Link to home
Start Free TrialLog in
Avatar of 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
      PrivateKey privateKey = (PrivateKey) _keyStore.getKey(privateKeyName, privateKeyPassword.toCharArray());
      Enumeration e = _keyStore.aliases();
              System.out.println("alais:" + (String)e.nextElement());
      if (privateKey == null)
                 throw new UrlAuthenticationException("No key " + privateKeyName + " found");
      Signature signature = Signature.getInstance("SHA1withRSA");
      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());

Avatar of joechina

Avatar of SkipFire


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.
if the input is not a multiple of 4, could you pad it with space or -?
Tried padding it front and back with everything I could think of.
sry, give me a couple day. I will try here. thx
Avatar of joechina

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
the keypassword parameter for your java function is the password you put when you export your PKCS12 file.
I know, I don't have access to the full java code, just the snippit that I posted here.  
I'm going to assume that this will work, I have no clue when I will get the password.