?
Solved

Decryption error

Posted on 2006-11-14
3
Medium Priority
?
1,024 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

762 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