TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Hari Babu
NA
83
0
Getting error ASN1 bad tag value met. in C#
Sep 24 2017 10:47 PM
I
am integrating thirdparty API and tryed to decrpt thirdparty result using private key
third party user using java to encrypt the result using public key . i am using C#.net
application to decrypt the data. third party user has given below instructions to decrypt the
text .
1)Those fields are in Base64URL format. So the first thing we need to do is to convert it to Base64.
2) After obtaining the Base64 values, we need to decode them. To do that, we used "base64 --decode" linux command.
3) After decoding all parts, we decrypt the secondary key with Merchant's private key.
below is my code which i am trying
key ="e4yDH3QAhnYtMRLPX-iRFJVn2Q1NGVRG6Rs5DEqb6F9tsMyyAggny831leDV-xXxm50LDlgO4EMdb_7iLdsoV2KyeRMBkYn8doARZDMu24Y8j55mQqaAB_na-ju2LiWSSNlPImUWtn1Peoh3esh01ia3mUWN2HKkg3sPzEa20-E";
string dummyData = key.Replace("-", "+");
dummyData= dummyData.Replace("_", "/");
dummyData= dummyData.Replace(" ", "+") ;
dummyData = dummyData.PadRight(dummyData.Length + (4 - dummyData.Length % 4) % 4, '=');
var convertbase64 = Convert.FromBase64String(dummyData);
//string decodedString = Encoding.UTF8.GetString(convertbase64);
string decodedString = Convert.ToBase64String(convertbase64);
string path = ConfigurationManager.AppSettings["Certpath"].ToString();
doDecrypt(decodedString.ToString());
private PKCS7 sntqPKCS7 = new PKCS7();
public string doDecrypt(string str2Decrypt)
{
string strAfterDecrypt = "";
string password = "Password";
try
{
log.Info("start Decrypt.");
var certificate = new X509Certificate2(ConfigurationManager.AppSettings["Certpath"].ToString(),
password);
strAfterDecrypt = sntqPKCS7.decryptMessage(str2Decrypt, certificate);
log.Info("strAfterDecrypt :" + strAfterDecrypt);
log.Info("doDecrypt Success.");
}
catch (Exception exp)
{
log.Info("doDecrypt (Err) : " + exp.Message);
}
return strAfterDecrypt;
Error :System.Security.Cryptography.CryptographicException: ASN1 bad tag value met.
Kindly help on this.
Reply
Answers (
0
)
What is cyber security?
PCI-DSS Compliance