Quantcast
Channel: Security
Viewing all articles
Browse latest Browse all 4737

RSA Encryption with Sha1

$
0
0

Hi,

Can any one please help me on this. Is it possible to sign the message by using below process  Generate the hash value by using SHA512 and sign it by using RSA SHA1

Below code is the example;

public string ComputeHashString(string Message)
{
string hex = string.Empty;
byte[] SignedhashValue;byte[] hashValue;
byte[] dataToSign = null; string PrivateKey = string.Empty;

try
{
//Convert data into bytes
dataToSign = Encoding.UTF8.GetBytes(Message);

//Get the Private key from .pem file
PrivateKey = GetKey();

using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
{
rsa.PersistKeyInCsp = false;
rsa.LoadPrivateKeyPEM(PrivateKey);

SHA512Managed sha512 = new SHA512Managed();

//Compute 512 Hash value of the converted bytes
hashValue = sha512.ComputeHash(dataToSign);

// Sign the hash
SignedhashValue = rsa.SignHash(hashValue, CryptoConfig.MapNameToOID("SHA1")); // Here its througing an error as Bad Hash IF I USE SHA1, iF I use SHA512 its ok but I need to sign by using SHA1
}

foreach (byte x in SignedhashValue)

{
hex += String.Format("{0:x2}", x);
}

return hex;

}
catch (Exception ex)
{
WriteFile("ComputeHashString--" + ex.Message, "FPXPKIServiceLog_" + DateTime.Today.ToString("ddMMyyyy") + ".txt");
return string.Empty;
}

}


Viewing all articles
Browse latest Browse all 4737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>