Question

decrypt file using pfx and password

Asked by: Znasev

I have a file that is encrypted for sending by e-mail by an application. I have pfx file, password and public key.
How can I decrypt the file?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-09-14 at 05:19:08ID24729274
Topics

Encryption for Network Security

,

Operating Systems Network Security

,

Windows Network Security

Participating Experts
2
Points
500
Comments
18

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Encrypt & Decrypt Functions
    Can anyone provide me with a simple encrypt and decrypt function that encrypt/decrypt a password
  2. Encryption and Decryption
    I developed one application in VB backend as a SQL server. In that iam getting data from database. I want to encrypt and decrypt that data. Can you Help me?
  3. Decryption
    Through lotus mail I get mail memo that has one file attached. That file has been encrypted with password. So I have to decrypt that file with password. I know the password. Can it be possible to decrypt that file with Lotus notes? Shrirang
  4. Encrypt/Decrypt  Password
    I have the config files/Shell scripts where the password is hardcoded to connect to the database(Oracle): Ex: sqlplus username/password The password should not be in clear text & should be encrypted before connecting to the backend. Oracle will not take encrypted passwor...
  5. Encryption/decryption of password.
    Hi, I am having problem with password encryption/decryption. I can successfully encrypt but when I do the decryption I am getting few exceptions like IllegalBlockSizeException, BadPaddingException. Below is the code which I have written and the exception I am getting whe...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: nociPosted on 2009-09-14 at 10:36:29ID: 25327576

A pfx file is a pkcs#12 formated file, that contains a private key + certificate..., you can import it in windows to store in the certificate folder.
Of you can use openssl to disect the file in its parts and use them accordingly.

 

by: DaveHowePosted on 2009-09-14 at 14:18:35ID: 25329441

I suspect he means he has a file secured by the public key - s/mime encoded.

openssl would decode that, if it is correctly formatted, but depending on how the file is encoded it might need a bit of scripting and ebcrypt.

 

by: ZnasevPosted on 2009-09-14 at 14:20:14ID: 25329457

I already imported it in windows, but I have no idea how to use it against the small encrypted txt file that I need to be decrypted.

 

by: nociPosted on 2009-09-14 at 15:27:01ID: 25329902

openssl smime --decrypt [--inform ? ] -in 'message-file' -inkey 'pfx-file'
if smime... extra options may apply.   see 'openssl smime --help' for more options

if rsa enconding 'openssl rsa --help' or 'openssl rsautl --help'
if rsa encoded files....

 

by: ZnasevPosted on 2009-09-15 at 01:45:09ID: 25332960

Properties from the imported pfx file are

Version: V3

Signature algorithm: sha1RSA

Public key: RSA(1024Bits)

I found that there is a password file also.
I tried both in Windows and Linux

1.
openssl rsautl -in inputFileName -out outputFileName -inkey keyfile.pfx -decrypt -passin fileContainingPassword

Invalid password argument "fileContainingPassword"
Error getting password

2.
openssl rsautl -in inputFileName -out outputFileName -inkey keyfile.pfx -decrypt -passin passwordFromTheFile

Invalid password argument "passwordFromTheFile"

Am I using the right tool?

 

by: ZnasevPosted on 2009-09-15 at 01:49:37ID: 25332984

Also tried

openssl rsautl -in inputFileName -out outputFileName -inkey keyfile.pfx -decrypt -passin file:fileContainingPassword

unable to load Private Key

 

by: nociPosted on 2009-09-15 at 07:17:06ID: 25335121

probably replace -inkey with -certin as a pfx contains a certificate. + public key; otherwise use -pubin for a public key.
(also check pkeyutl, it seems rsautl is replaced by it).

file:... is the right form for a passin.

I am not sure what you got..., the pfx seems to be a public key, is the other key  a private key?; you might need -decrypt with -pubin?
From the example: the way it meant to be used....
Encription:
openssl rsautl -encrypt -pubin -inkey publickey.pem -in plain.txt -out cipher.txt                  

Decryption:
openssl rsautl -decrypt -inkey privatekey.pem -in cipher.txt -out plainRcv.txt
- This will ask for a passphrase/password of the privatekey.pem if encrypted...., -passin should also work.

You can derive a public key from a private key, but not the other way around...:
openssl rsa -in privatekey.pem  -pubout -out publickey.pem
- This will ask for a passphrase/password of the privatekey.pem if encrypted...., -passin should also work.

 

by: ZnasevPosted on 2009-09-15 at 23:25:52ID: 25342456

I found that pfx file conains both private key and certificate and is password protected. I used

openssl pkcs12 -in pfxFile.pfx -out pemFile.pem

to derive a pem file. It asked for a password (I entered the pass I have for the pfx file) and after entering, before creating pem file asked for a pass phrase (I guess password to be used when decrypting), so I entered some word.  I used this pem file for decrypting

openssl rsautl -decrypt -inkey pemFile.pem -in encryptedFile.crp -out test.txt
Enter pass phrase for pemFile.pem:
RSA operation error
6421:error:0406506C:rsa routines:RSA_EAY_PRIVATE_DECRYPT:data greater than mod len:rsa_eay.c:512:

 

by: nociPosted on 2009-09-16 at 00:33:36ID: 25342861

The 2nd passphrase is to protect the .pem file, if you press enter you would have an unprotected private key....
Ok, then your data is very probably bsae64 encoded...

using: openssl enc -a -d -in encryptedFile.crp -out encryptedFile.crp.bin
you can make this binary, and then decrypt the binary file.

 

by: ZnasevPosted on 2009-09-16 at 02:37:59ID: 25343577

openssl enc -a -d -in File.crp -out File.crp.bin


openssl rsautl -decrypt -inkey keyPem.pem -in File.crp.bin -out test.txt
Enter pass phrase for keyPem.pem:
RSA operation error
10154:error:0406506C:rsa routines:RSA_EAY_PRIVATE_DECRYPT:data greater than mod len:rsa_eay.c:512:

 

by: nociPosted on 2009-09-16 at 05:05:07ID: 25344597

was the message bare to begin with....

no headers & foorters (lines above & below a line with ---'s and a BEGIN or END tag, including those tagged lines)

You will then have a blob of text that contains only readble text (digits, alphabetics (lower & uppercase) + reading signs (+-()/\ etc.)
the text will most probably end with a couple of == signs.

This blob is the one that needs to be decoded.

 

by: ZnasevPosted on 2009-09-17 at 04:25:44ID: 25354785

Before

openssl enc -a -d -in File.crp -out File.crp.bin

File had header and footer and the lines in between  were readable with ^M mark at the end of them

after

openssl enc -a -d -in File.crp -out File.crp.bin

It is completely unreadable

Tried to decode only lines that had ^M mark (lines that are readable), but same message "data greater than mod len:rsa_eay.c:512:".

 

by: nociPosted on 2009-09-17 at 06:01:38ID: 25355565

on a linux system jou dont want the ^M character.., although I would expect them to be ignored.
The binary blob is expected to be unreadable... (it is compressed data, which is then encrypted using binary keys).

I found some references that this sometimes happens with messages that were created using pgp 9?

Then another thing, could this be a s/mime formatted mail, it has been asked before, but (silently?) ignored?
S/Mime looks almost like regular mime, but supports encrypted content.

Then the command would become:

openssl smime -decrypt -in File.crp -recip mycert.pem -inkey key.pem

 

by: ZnasevPosted on 2009-09-17 at 23:10:50ID: 25363221

The pem file I have is derived from pfx file, so I have only one. I think that both certificate and key are in it.
I tried openssl smime -decrypt -in File.crp -recip mycert.pem

I tried various combinations, but everytime I got
6397:error:2107A087:PKCS7 routines:SMIME_read_PKCS7:no content type:pk7_mime.c:296:

Windows imported PFX file into certificates without any problem and states that I have a key that corresponds to the certificate. I guess windows can reveal what type of information is stored in pfx file, so is there a way to find what kind of encryption is used and which tool should be used for decryption?

 

by: nociPosted on 2009-09-18 at 00:23:55ID: 25363483

You don't need to look at the key, but at the encrypted file.
There should be hints about it's format...

IF there is stuff like this inside:

MIME-Version: 1.0
Content-Type: multipart/signed;
  protocol="application/x-pkcs7-signature";
  micalg=sha1;
  boundary="------------ms010504060809030906030009"

Later in the mail:
--------------ms010504060809030906030009
Content-Type: application/x-pkcs7-signature; name="smime.p7s"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7s"
Content-Description: S/MIME Cryptographic Signature

indicating a signature. can also be encrypted content.
then it's s/mime

If there is no mentioning og content-type: multipart/signed... then you have another format
Here you can also see it is pkcs7 structured.

PGP headers are like:

-----BEGIN PGP SIGNED MESSAGE-----
blah blah
-----BEGIN PGP SIGNATURE-----
Version: PGP Desktop 9.0.6 (Build 6060)

blah
-----END PGP SIGNATURE-----

Other format do exist too... basically this tells you the tool to use for encryption...
PGP encrypted file cannot be decrypted with OPENSSL and vice versa, it's different technology.
Within both format there are sub formats....

 

by: ZnasevPosted on 2009-09-18 at 02:09:52ID: 25364007

There is nothing readable in the encrypted text. The file is intended for me to send to somebody as attachment by mail and is not encrypted mail message. Imported certificate in Windows states that it's intended purposes are  "Secure EmailI". I have public key, pfx file and file that contains the password for the pfx. The program that creates the encrypted file is installed on my computer and uses the files above for encryption. The data that is encrypted is created by me in the installed program. the problem is that now I have all the encrypted files created by me and I need original files that are ordinary text files.

 

by: nociPosted on 2009-09-18 at 03:10:32ID: 25364337

How does the installed program propose to decrypt an encrypted file when received by someone else?
Besides the 'standard way' (PGP, S/MIME) anybody can device their own way off course, that doesn't exactly fit with the tools for 'standard' use
Usage of a pfx file, public/private key seem to hint to openssl.

Besides mime formated input (with mime headers openssl smime can also handle raw forms)
it might need either '-inform DER' or '-inform PEM' with  -decrypt if the input has no mime structure.

 

by: ZnasevPosted on 2009-09-24 at 23:08:01ID: 31628349

I Didn't solve the problem, but I am giving the points to noci for trying to help me for so long.

Thank you anyway

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...