EldoS | Feel safer!

Software components for data protection, secure storage and transfer

SBPGPExceptions.EElPGPInvalidPacketException: Invalid PGP packet

Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.
#1488
Posted: 10/20/2006 10:09:27
by Rav Panesar (Basic support level)
Joined: 10/19/2006
Posts: 14

I have entered the following code and keep on getting a SBPGPExceptions.EElPGPInvalidPacketException: Invalid PGP packet error

The strange thing is when using LoadFromFile and i specify a file name that works fine. I am using .net 2.0. The following is the code that i am using. Thanks for your help in advance


'we need to create a public/private key streams
strPublicKey = System.Configuration.ConfigurationManager.AppSettings("Pub").ToString
strPrivateKey = System.Configuration.ConfigurationManager.AppSettings("PRI").ToString

'Create them into streams
bPublic = (New UnicodeEncoding).GetBytes(strPublicKey)
bPrivate = (New UnicodeEncoding).GetBytes(strPrivateKey)
Dim PublicKeyStream As New System.IO.MemoryStream(bPublic)
Dim PrivateKeyStream As New System.IO.MemoryStream(bPrivate)

'Get the varibles
strUserID = "130413"
strCompanyReference = "HRG998877"
strLangaugeID = "1237"

'Set the encryption
pgpWriter.EncryptionType = SBPGP.TSBPGPEncryptionType.etBoth

'Get the license
strLicense = System.Configuration.ConfigurationManager.AppSettings("HRGPrivate").ToString

'Set the license
'SBUtils.Unit.SetLicenseKey(“xxxxxxxxx”)


'Load the private/secret keys
publicKey.LoadFromStream(PublicKeyStream)
secretKey.LoadFromStream(PrivateKeyStream)

#1489
Posted: 10/20/2006 10:26:27
by Ken Ivanov (EldoS Corp.)

Quote
bPublic = (New UnicodeEncoding).GetBytes(strPublicKey)
bPrivate = (New UnicodeEncoding).GetBytes(strPrivateKey)
Dim PublicKeyStream As New System.IO.MemoryStream(bPublic)
Dim PrivateKeyStream As New System.IO.MemoryStream(bPrivate)

Not sure if the above code is correct. PGP packets may contain binary data, so there can appear certain problems if these data are interpreted using some text encoding.

From the other side, if you are sure that your keys are stored in *textual* format, please use ASCIIEncoding class instead of UnicodeEncoding. This should solve the problem.
#1490
Posted: 10/20/2006 10:41:49
by Rav Panesar (Basic support level)
Joined: 10/19/2006
Posts: 14

I have changed the code to use the following

bPublic = (New ASCIIEncoding).GetBytes(strPublicKey)
bPrivate = (New ASCIIEncoding).GetBytes(strPrivateKey)


and still get the following error, although i am getting the keys without the headers, would that make a difference? I am also storing the key's in the web.config file as a text value so the key itself is text.

SBPGPExceptions.EElPGPInvalidPacketException: Invalid PGP packet
at SBPGPEntities.TElPGPStreamProcessor.Process(Object AReadUserData, Object AWriteUserData)
at SBPGPKeys.TElPGPKeyring.Load()
at SBPGPKeys.TElPGPKeyring.Load(Stream APublic, Stream ASecret, Boolean Clear)
at SBPGPKeys.TElPGPPublicKey.LoadFromStream(Stream Stream)
#1491
Posted: 10/20/2006 11:07:08
by Rav Panesar (Basic support level)
Joined: 10/19/2006
Posts: 14

i have copied the exact key and used AscIIEncoding and now it works, at first i was putting the key onto one line which was causing an error. However I have got a problem with the private key as that use's the following header


-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: SecureBlackbox 4 (PGPBlackbox)


-----END PGP PUBLIC KEY BLOCK-----



i get the following error to do with this header, thanks again




SBPGPExceptions.EElPGPDearmoringStreamException: Invalid header line at SBPGPStreams.TElPGPDearmoringStream.@12$ProcessBlock$ProcessHeaders(TElPGPDearmoringStream Self) at SBPGPStreams.TElPGPDearmoringStream.ProcessBlock(Byte[] Buffer) at SBPGPStreams.TElPGPDearmoringStream.DataAvailable() at SBPGPKeys.TElPGPKeyring.Load() at SBPGPKeys.TElPGPKeyring.Load(Stream APublic, Stream ASecret, Boolean Clear) at SBPGPKeys.TElPGPSecretKey.LoadFromStream(Stream Stream) at TestSSO_v1.SignAndEncryptToken() in c:\inetpub\wwwroot\PortalComponents\TestSSO_v1.aspx.vb:line 102
#1493
Posted: 10/20/2006 12:50:10
by Ken Ivanov (EldoS Corp.)

This exception is usually caused by some header formatting errors. Unfortunately, I cannot help you without seeing what exactly you are passing to the TElPGPKeyring.Load() method.

Actually, since file-based TElPGPKeyring.Load() method works fine for you, it's a good idea to find out the differences between data contained in the key files and contents of bPublic and bPrivate byte arrays. This should help to find a reason for the error.
#1504
Posted: 10/23/2006 03:57:41
by Rav Panesar (Basic support level)
Joined: 10/19/2006
Posts: 14

Hi when the code is running I am using the following code

strPublicKey = System.Configuration.ConfigurationManager.AppSettings("Public").ToString
strPrivateKey = System.Configuration.ConfigurationManager.AppSettings("Private").ToString

'Create them into streams
bPublic = (New ASCIIEncoding).GetBytes(strPublicKey)
bPrivate = (New UnicodeEncoding).GetBytes(strPrivateKey)
Dim PublicKeyStream As New System.IO.MemoryStream(bPublic)
Dim PrivateKeyStream As New System.IO.MemoryStream(bPrivate)



'Set the encryption
pgpWriter.EncryptionType = SBPGP.TSBPGPEncryptionType.etBoth


'Set the license
'SBUtils.Unit.SetLicenseKey(strLicense.ToString)


'Load the private/secret keys
publicKey.LoadFromStream(PublicKeyStream)
secretKey.LoadFromStream(PrivateKeyStream)



it passes the first loadfromstream and fails on the sencond loadfromstram part here the following is from the web confid with the keys removed. It seems like only the headers are not the same, do the headers have to be exactly the same for both keys?




<add key="Public" value="
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.5 (MingW32)

PUBLIC KEY


-----END PGP PUBLIC KEY BLOCK-----"></add>



<add key="Private" value="-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.5 (MingW32)

PRIVATE KEY

-----END PGP PUBLIC KEY BLOCK-----">









however if i change the secondkey.load and load it from file like the following it works fine.

secretKey.LoadFromFile("c:\keys\secring.gpg")



Thanks
#1505
Posted: 10/23/2006 04:09:56
by Ken Ivanov (EldoS Corp.)

Quote
bPublic = (New ASCIIEncoding).GetBytes(strPublicKey)
bPrivate = (New UnicodeEncoding).GetBytes(strPrivateKey)

You have to use ASCIIEncoding for private key material too.
#1506
Posted: 10/23/2006 04:22:18
by Rav Panesar (Basic support level)
Joined: 10/19/2006
Posts: 14

Hi completely forgot about that as I have tried all different encoding

This is the situation now with all the correct code

strPublicKey = System.Configuration.ConfigurationManager.AppSettings("Public").ToString
strPrivateKey = System.Configuration.ConfigurationManager.AppSettings("Private").ToString

'Create them into streams
bPublic = (New ASCIIEncoding).GetBytes(strPublicKey)
bPrivate = (New ASCIIEncoding).GetBytes(strPrivateKey)
Dim PublicKeyStream As New System.IO.MemoryStream(bPublic)
Dim PrivateKeyStream As New System.IO.MemoryStream(bPrivate)



'Set the encryption
pgpWriter.EncryptionType = SBPGP.TSBPGPEncryptionType.etBoth

'Get the license
strLicense = System.Configuration.ConfigurationManager.AppSettings("License").ToString

'Set the license
SBUtils.Unit.SetLicenseKey(strLicense.ToString)

'Load the private/secret keys
publicKey.LoadFromStream(PublicKeyStream)
secretKey.LoadFromStream(PrivateKeyStream)



This is the web.config

<add key="Public" value="
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.5 (MingW32)

PUBLIC KEY
-----END PGP PUBLIC KEY BLOCK-----"></add>
<add key="Private" value="-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: SecureBlackbox 4 (PGPBlackbox)

PRIVATE KEY
-----END PGP PUBLIC KEY BLOCK-----"></add>


And now I get the following error from the loading from stream on the secret key


SBPGPExceptions.EElPGPInvalidKeyException: Invalid PGP key data at SBPGPKeys.TElPGPSecretKey.LoadFromStream(Stream Stream) at TestSSO_v1.SignAndEncryptToken() in c:\inetpub\wwwroot\PortalComponents\TestSSO_v1.aspx.vb:line 102



Is there anyway to debug this?

I think i know what is going wrong but do not know how to correct it, when reading from the secret file it is a .gpg file, i have used the demo file to export it to a .asc file but I think it is that conversion that has gone wrong, what it the correct way to change the .gpg file to a text based file.


Thanks for your help







Thanks for your help.
#1507
Posted: 10/23/2006 04:32:42
by Ken Ivanov (EldoS Corp.)

Hmm, it seems that the secret key gets corrupted when put to (or extracted from) the web.config file. Please try to save the data contained in bPrivate array to disk file and compare it to the original file in order to find the differences. Then we will be able to provide you further recommendations on solving the issue.
#1515
Posted: 10/23/2006 08:18:43
by Rav Panesar (Basic support level)
Joined: 10/19/2006
Posts: 14

yes there is a corruption for the last 60 characters of the key for some reason, the rest of the key is the same. Is there a better way to get the key into a text format? I have used your demo keys application to export the key into a .asc file?
Thanks
Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.

Reply

Statistics

Topic viewed 14413 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!