Solved

Decryption error

Posted on 2006-11-14
3
1,019 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
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
joechina earned 500 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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Run time Error 4 48
Google Directions API to Map URL -C#? 3 27
PrintingFoundIt(Almost!(Damn!)) 1 27
C# Gridview 1 33
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

803 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