after generation encrypt the token with SHA1 with RSA using Asp.net C#
private key:"65e365bd06f7f54a5282a63278bb21c2";
json string:{\"UserID\":\"1\",\"UserName\":\"Ayyappa\",\"txnId\":\"123456\",\"customerMob\":\"8569896857\",\"lname\":\"lakshman\",\"name\":\"Balasubbiramani\",\"mname\":\"ram\",\"productCode\":\"DMT\",\"address\":\"Mumbai\",\"dateOfBirth\":\"05/10/1982\",\"agentId\":\"CUSTOMER123456\",\"partnerId\":\"761\",\"kycStatus\":\"0\",\"pancardStatus\":\"0\",\"identityDocType\":\"0\",\"identityDocNo\":\"BgQkkDr14...\",\"channel\":\"4\",\"isOTPValidated\":\"0\",\"hashKey\":\"9f3f9eb0451e8c2e3955551c57458072\"}";


Rajkiran SwainRank #165 · 14.4K reputationPosted May 17, 2023, 7:03 AM EDT
Make sure that the cryptographic provider you are using is compatible with the version of .NET Framework you are targeting. You can check the documentation for the provider to see which versions of .NET it supports.
Check that you have installed any necessary updates or patches for the .NET Framework.
Make sure that the private key you are passing is valid and that the JSON string you are using is well-formed.
If you are using a third-party cryptographic library, make sure that you have correctly installed and configured it.
If none of these solutions work, you may need to provide more information about the specific cryptographic provider you are using and the code you are using to generate the token.
Rajkiran SwainRank #165 · 14.4K reputationPosted May 17, 2023, 12:55 AM EDT
using System; using System.Security.Cryptography; using System.Text; public class TokenGenerator { private static string privateKey = "65e365bd06f7f54a5282a63278bb21c2"; private static string jsonString = "{\"UserID\":\"1\",\"UserName\":\"Ayyappa\",\"txnId\":\"123456\",\"customerMob\":\"8569896857\",\"lname\":\"lakshman\",\"name\":\"Balasubbiramani\",\"mname\":\"ram\",\"productCode\":\"DMT\",\"address\":\"Mumbai\",\"dateOfBirth\":\"05/10/1982\",\"agentId\":\"CUSTOMER123456\",\"partnerId\":\"761\",\"kycStatus\":\"0\",\"pancardStatus\":\"0\",\"identityDocType\":\"0\",\"identityDocNo\":\"BgQkkDr14...\",\"channel\":\"4\",\"isOTPValidated\":\"0\",\"hashKey\":\"9f3f9eb0451e8c2e3955551c57458072\"}"; public static string GenerateToken() { // Convert private key to byte array byte[] privateKeyBytes = Encoding.UTF8.GetBytes(privateKey); // Convert JSON string to byte array byte[] jsonBytes = Encoding.UTF8.GetBytes(jsonString); // Create SHA1 with RSA crypto service provider using (SHA1Managed sha1 = new SHA1Managed()) { // Hash the private key bytes byte[] hashedPrivateKey = sha1.ComputeHash(privateKeyBytes); // Create RSA provider with the hashed private key using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) { rsa.ImportCspBlob(hashedPrivateKey); // Encrypt the JSON bytes using RSA byte[] encryptedBytes = rsa.Encrypt(jsonBytes, false); // Convert the encrypted bytes to a string representation string encryptedToken = Convert.ToBase64String(encryptedBytes); return encryptedToken; } } } } // Usage string token = TokenGenerator.GenerateToken();Nagaveni Katari191 reputationPosted May 17, 2023, 5:04 AM EDT
Nagaveni Katari191 reputationPosted May 19, 2023, 5:07 AM EDT
Nagaveni Katari191 reputationPosted May 19, 2023, 5:10 AM EDT
string privateKey = "65e365bd06f7f54a5282a63278bb21c2";
string jsonData = {\"UserID\":\"1\",\"UserName\":\"Ayyappa\",\"txnId\":\"123456\",\"customerMob\":\"8569896857\",\"lname\":\"lakshman\",\"name\":\"Balasubbiramani\",\"mname\":\"ram\",\"productCode\":\"DMT\",\"address\":\"Mumbai\",\"dateOfBirth\":\"05/10/1982\",\"agentId\":\"CUSTOMER123456\",\"partnerId\":\"761\",\"kycStatus\":\"0\",\"pancardStatus\":\"0\",\"identityDocType\":\"0\",\"identityDocNo\":\"BgQkkDr14...\",\"channel\":\"4\",\"isOTPValidated\":\"0\",\"hashKey\":\"b2b7e6c8f6f011e2b6396c4d36d4ecd6\"}";
public string SignedToken(string privateKey, string data)
{
byte[] privateKeyBytes = HexStringToByteArrays(privateKey);
using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
{
RSAParameters privateKeyParams = rsa.ExportParameters(true);
privateKeyParams.D = privateKeyBytes;
rsa.ImportParameters(privateKeyParams);
byte[] dataBytes = Encoding.UTF8.GetBytes(data);
byte[] signatureBytes = rsa.SignData(dataBytes, HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1);
string signedString = Convert.ToBase64String(signatureBytes);
return signedString;
}
}
private byte[] HexStringToByteArrays(string hex)
{
int length = hex.Length;
byte[] bytes = new byte[length / 2];
for (int i = 0; i < length; i += 2)
{
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
}
return bytes;
}
This is my code