Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Decryption error

Posted on 2006-11-14
3
Medium Priority
?
1,026 Views
Last Modified: 2008-02-01
I am trying to decrypt a string encrypted in Java.  My decryption code is below, but it generates a CryptographicException "The object cannot be found" on the line:
    X509Certificate2 myCertificate = new X509Certificate2(@"c:\signon_keystore.p12", password);
What am I doing wrong to decrypt this?


        static void Start(string[] args)
        {
            StreamReader sr = new StreamReader(File.OpenRead(@"c:\Source.txt"));
            string source = sr.ReadToEnd();
            string data = Regex.Match(source, "(?<=user=)([^&]*)").Value;
            string signData = Regex.Match(source, "(?<=authSignature=)(.*$)", RegexOptions.Multiline).Value;
            bool isTrue = VerifyData(HttpUtility.UrlDecode(data), HttpUtility.UrlDecode(signData));
            MessageBox.Show(isTrue.ToString());
        }

        static bool VerifyData(string data, string signature)
        {
            string password = "123456";
            X509Certificate2 myCertificate = new X509Certificate2(@"c:\signon_keystore.p12", password);
            RSACryptoServiceProvider provider1 = (RSACryptoServiceProvider)myCertificate.PublicKey.Key;
            byte[] sb = Convert.FromBase64String(signature);
            byte[] db = (new ASCIIEncoding()).GetBytes(data);
            return provider1.VerifyData(db, new SHA1CryptoServiceProvider(), sb);
        }
0
Comment
Question by:SkipFire
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
joechina earned 2000 total points
ID: 17940409
Your key file might have problem.
Where do you get the key file?
0
 
LVL 4

Author Comment

by:SkipFire
ID: 17940464
I got the key file from our java team.  They are using it to encrypt, and I have been told that another java app is decrypting with it.  Unfortunately I have trouble getting any sort of information from our java team.
0
 
LVL 13

Expert Comment

by:joechina
ID: 17940538
Are you sure this is a PKCS12 key file?
Ok, Try this,

Under your XP, double click this file, and you should get a certificate import wizard.
If you can successfully import the key, then open IE , go to "internet option" -> "content" -> "certificate"
find the certificate you just imported. (hopefully, it's in your personal store)

then export the without private key. to DER format. Save it to a file called 'xxxx.cer'

Then try modify your code to
X509Certificate2 myCertificate = new X509Certificate2(@"xxxx.cer");

Good Luck
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question