Solved

Decryption error

Posted on 2006-11-14
3
1,018 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Achieve json result 2 65
LINQ - C# to VB convertion 12 48
Wav problem 4 19
rest webservice call over https via c# 6 29
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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now