WrongPrivateKeyException

53 views
Skip to first unread message

vgathmann

unread,
Jan 18, 2012, 12:03:18 PM1/18/12
to DidiSoft Forum
I've been using PGP Command Line product for a few years and we have
been encrypting files that we send to our bank. I want to encapsulate
this process (which is currently multi-part) into a stand-alone
C# .NET console application. When I use the following code to decrypt
existing file, I get a 'WrongPrivateKeyException"

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DidiSoft.Pgp;

namespace PositivePaySend
{
class Program
{
static void Main(string[] args)
{
// bool asciiArmor = true;
PGPLib pgp = new PGPLib();
pgp.DecryptFile(@"c:\testrun\PGP_ARP_ARACKR_NJFS103N.asc",
@"c:\testrun\Pictorial.asc",
"XXXXXXX", @"c:\testrun
\PGP_ARP_ARACKR_NJFS103N.txt");

}
}
}

Note: passphrase has been removed from example for security reasons.

Do I have to 'register' the encrypting party's public key? I've looked
through the documentation, but cannot find anything related to this
issue.

Thanks,

didisoft

unread,
Jan 18, 2012, 12:53:47 PM1/18/12
to DidiSoft Forum
Hello Sir,

You shall be able to use the trial version without exception.

Can you please verify that the file Pictorial.asc contains a
--- BEGIN PGP PRIVATE KEY --- section ?

There is a possibility that you have exported only the public key part
of your key pair.

If you tell me the version of PGP command line you are usinng I can
send you the additional
parametter needed to export the private key too.

Best Regards,
Peter Kalef
DidiSoft Ltd.

vgathmann

unread,
Jan 18, 2012, 1:24:12 PM1/18/12
to DidiSoft Forum

You're correct. The 'Pictorial.asc' file only contains the public key.

I'm using PGP Command Line Version 10.2

How do I export the private key? I'm assuming that is in the
'secring.skr' file.

Thank you for your prompt reply and assistance.

didisoft

unread,
Jan 18, 2012, 1:31:49 PM1/18/12
to DidiSoft Forum
Hello Mr. Gathmann,

You shall use
pgp --export-key-pair XXX
instead of
pgp --export XXX

Kind Regards,
Peter Kalef
DidiSoft Ltd.

vgathmann

unread,
Jan 18, 2012, 1:51:24 PM1/18/12
to DidiSoft Forum
Peter,

I have problem with that since there are two keys with the same name.
I tried using the following command to export the one that I need (I
know from my decryption scripts which key id i need):

pgp --export-key-pair lsamuels --passphrase "********" --cert
0x0621B2BB

I still get this message: lsamuels:export key pair (2003:too many
matches for key to edit)

Is there a way to delete the unused 'lsamuels' key from the keychain?

Thanks again for your prompt support.

Vince G.

vgathmann

unread,
Jan 18, 2012, 2:01:19 PM1/18/12
to DidiSoft Forum
Peter,

Thanks for your help. I figured out how to export the pair that I
needed by using the 'cert id' instead of the name of the key when
performing the key export.

I'm all set now. I need to do a couple of more tests, then I will
purchase the library.

Thank you very much for all of your assistance.

Regards,
Vince G.

didisoft

unread,
Jan 18, 2012, 3:03:37 PM1/18/12
to DidiSoft Forum
H Vince,

I'm glad that you succeeded.

Please let me know if I can be of any other help in the future

Cheers,
Peter

Vladimir Agajanov

unread,
May 25, 2012, 12:07:24 PM5/25/12
to didisof...@googlegroups.com
Hello To All,
 
I happened to have similar problem of WrongPrivateKeyException when I try to decrypt the file that was sent to me by a vendor, who encrypted it with the PublicKey that I provided...
 
In my case I don't have a command Line PGP software, but I used GenerateKeyPair method of PGPLib, saved it to Store and then Exported Public Key to one file and Private Key to enother by calling  ExportPublicKey and ExportPrivateKey methods of PGPLib instance correspondingly...
 
I was wondering if it would be possible to get some assistance to resolve the problem I am experiencing...
 
note:  The vendor is UNIX based, and I am running Windows 2008 Server (64bit), if it matters...
 
Thanks for any help,
 
Vladimir

didisoft

unread,
May 25, 2012, 12:27:46 PM5/25/12
to DidiSoft Forum
Hi Vladimir,

Can you check that you are supplying the key that you have exported
with ExportPrivateKey to the decryption method?

Regards,
Peter Kalef

Vladimir Agajanov

unread,
May 25, 2012, 2:26:00 PM5/25/12
to didisof...@googlegroups.com
Hello Peter,
 
Thank you very much for your response...
 
Indeed it was my problem... I regenerated KeyPair... Stored it in the store and then Exported both Keys... It worked very nicely...
 
Thanks again!
 
Vladimir

didisoft

unread,
May 25, 2012, 2:31:54 PM5/25/12
to DidiSoft Forum
No problem Vladimir,

You can also check the example visual key tool KeyToolCS (KeyToolVB
for VB.NET)
that ships with the library. It is located in the \Examples folder
under the library installation directory.

Please let me know if you need any other help.

Cheers,
Peter
Reply all
Reply to author
Forward
0 new messages