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(privateKe
yName, privateKeyPassword.toCharA
rray());
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("SHA
1withRSA")
;
signature.initSign(private
Key);
signature.update(authStrin
g.getBytes
());
byte[] sig1 = signature.sign();
String base64 =Base64.encodeBytes(sig1);
String urlFragment = "user=" + URLEncoder.encode(authStri
ng,"UTF-8"
) + "&authSignature=" + URLEncoder.encode(base64,"
UTF-8");
return urlFragment;
}
catch (Exception e)
{
throw new UrlAuthenticationException
("UrlAuthe
nticationE
xception: " + e.toString());
}
}
}
Start Free Trial