Results 1 to 4 of 4

Thread: decrypt p7m file in C# or .NET with privateKey from file

  1. #1
    Join Date
    Dec 2011
    Posts
    2

    decrypt p7m file in C# or .NET with privateKey from file

    Hi,
    Hopefully someone can help me with code because I am working on it 3 months without any success. I tried almost anything from internet but nothing does not work.

    Problem: I have encrypted file p7m (size 158KB) (it is crypted text). I have certificate in file pfx, under password "a". In this certificate is the public key which is needed to decrypt p7m file.

    I need something that will read xyyv.p7m file, decrypt it with public key, and save it as XYZ.xyz

    I do not put here any my code to do not confuse you. thanks

  2. #2
    Join Date
    Jan 2006
    Posts
    605

    Re: decrypt p7m file in C# or .NET with privateKey from file

    I think that you need to start with the EnvelopedCms class and maybe use the Decode () method followed by the Decrypt method. It is hard to figure out from the documentation, but this page may help: http://msdn.microsoft.com/en-us/libr...=VS.90%29.aspx

  3. #3
    Join Date
    Dec 2011
    Posts
    2

    Re: decrypt p7m file in C# or .NET with privateKey from file

    Quote Originally Posted by janos™ View Post
    I think that you need to start with the EnvelopedCms class and maybe use the Decode () method followed by the Decrypt method. It is hard to figure out from the documentation, but this page may help: http://msdn.microsoft.com/en-us/libr...=VS.90%29.aspx
    I have files already in C: drive. So open the file is no problem. It could be easily read. Next steps to decrypt these bytes by private key from pfx file, or from installed at PC, simply does not work for me. The principle is simple:

    1. read file to memory
    2. read private key from pfx file
    3. decrypt file in memory by private key
    4. save decrypted text

    ...but #2 and #3 does not work.

    for #2 I have this code:
    X509KeyStorageFlags flags = X509KeyStorageFlags.Exportable;
    X509Certificate2 cert = new X509Certificate2("my.pfx", "somepass", flags);
    RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)cert.PrivateKey;
    RSAParameters rsaParam = rsa.ExportParameters(true);


    but I have problem to use this info in #3 part - use it in decryption.

  4. #4
    Join Date
    Dec 2007
    Posts
    2,291

    Re: decrypt p7m file in C# or .NET with privateKey from file

    To create this container, you can use pvk2pfx:
    Code:
    pvk2pfx -spc CA.cer -pvk CA.pvk -pfx CA.pfx
    (If you don't specify -pfx CA.pfx, it will launch the interactive interface, in which case you need to tick the box to export the private key.)

    Then, try to decrypt using that pfx/p12 file instead.

Similar Threads

  1. How to decrypt game file for Saints Row: The Third
    By AdaraKhan in forum Video Games
    Replies: 5
    Last Post: 17-11-2011, 10:40 AM
  2. Replies: 3
    Last Post: 28-01-2011, 06:26 AM
  3. Replies: 5
    Last Post: 14-01-2011, 07:42 PM
  4. Replies: 1
    Last Post: 20-04-2010, 08:04 PM
  5. decrypt file after formatting xp
    By sayanmaji in forum Operating Systems
    Replies: 2
    Last Post: 25-04-2009, 12:22 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,630,880.99644 seconds with 17 queries