Solved

Decryption error

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

12 Experts available now in Live!

Get 1:1 Help Now