EldoS | Feel safer!

Software components for data protection, secure storage and transfer

How to Load, verify, and set Trust of Public Key

Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.
#8735
Posted: 01/26/2009 15:03:50
by David Yee (Standard support level)
Joined: 01/26/2009
Posts: 8

Just beginning to test eldos SecureBlackbox OpenPGPBlackbox in my VB2008 app…trying to:

1) load, verify, and set trust level (completely trust) client’s public PGP key,
2) set output stream to existing string “strOutputEverything”,
3) set output file to existing string “strOutputFileName” [this is to be an encrypted text file which we will ftp transfer],
4) actually encrypt and save the encrypted output file.

I have installed the components in my toolbox and references (to SecureBlackbox.PGP.dll and SecureBlackbox.dll) in my project, and am at step #1 above. The line:
“SBPGPKeys.TElPGPPublicKey.LoadFromFile("DMCHSAWW.asc")”
is giving me “Reference to a non-shared member requires an object reference.” error. Intellisense gives me the “SBPGPKeys” and “TElPGPPublicKey” items, but not the “LoadFromFile”. What am I doing wrong?

I have also tried setting the trust level of the key in the next line:
"SBPGPKeys.TElPGPPublicKey.TElPGPKeyTrust = SBPGPConstants.Unit.SB_PGP_SIGTRUST_COMPLETETRUST"
is giving me "'TElPGPKeyTrust' is not a member of 'SBPGPKeys.TElPGPPublicKey'".

I'm noticing that Intellisense is giving me the "TEl..." items (for Pascal?) instead of the "El..." items (for VB) that I see in the documentation. Have I added references to the wrong dll's?
#8743
Posted: 01/27/2009 08:59:41
by Ken Ivanov (EldoS Corp.)

Thank you for your interest in our products.

Quote
1) load, verify, and set trust level (completely trust) client’s public PGP key,

To load the key, please use TElPGPKeyring.Load() method. If you need to load only a public key, feel free to pass Nothing as secret key parameter.

Please see a how-to article regarding key signature validation.

Quote
2) set output stream to existing string “strOutputEverything”,
3) set output file to existing string “strOutputFileName” [this is to be an encrypted text file which we will ftp transfer],
4) actually encrypt and save the encrypted output file.

Please use TElPGPWriter class to protect (either encrypt, sign or both encrypt and sign) a message. In particular, use its Encrypt() or EncryptFile() method to encrypt data contained in a stream or a file, respectively.

Quote
The line:“SBPGPKeys.TElPGPPublicKey.LoadFromFile("DMCHSAWW.asc")”
is giving me “Reference to a non-shared member requires an object reference.” error.

Do not use TElPGPPublicKey.LoadFromXXX() methods. All the keys should be loaded using TElPGPKeyring.Load() method.

Quote
I'm noticing that Intellisense is giving me the "TEl..." items (for Pascal?) instead of the "El..." items (for VB) that I see in the documentation. Have I added references to the wrong dll's?

You did everything right. "ElXXX" is just an alias for "TElXXX", the classes are named in "TElXXX" way indeed.

The developer will answer about your trust-related questions a bit later.
#8744
Posted: 01/27/2009 09:05:15
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 450

And about trust values - they are used only with keys, stored in keyrings, to save the chosen by user trust level. And such trust flags are not saved while exporting keys from keyrings.
#8745
Posted: 01/27/2009 12:42:42
by David Yee (Standard support level)
Joined: 01/26/2009
Posts: 8

Thank you for your prompt replies...I'm still having a problem with loading the keyring.
***********************************************************************
Both of these lines give me the same error "Overload resolution failed because no accessible 'Load' accepts this number of arguments."

TElPGPKeyring.Load("DMCHSAWW.asc")

SBPGPKeys.TElPGPKeyring.Load("DMCHSAWW.asc")
***********************************************************************
Both of these lines give me this error: "Reference to a non-shared member requires an object reference."

TElPGPKeyring.Load("DMCHSAWW.asc", "", True)

SBPGPKeys.TElPGPKeyring.Load("DMCHSAWW.asc", "", True)
***********************************************************************

What is the correct way to call the methods?
#8746
Posted: 01/27/2009 14:22:20
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 450

You are trying to call these methods without class member, i.e. you should at first create object of type TElPGPKeyring (like keyring = new TElPGPKeyring()), and only after that call keyring.Load("pubring.pkr", "secring.skr");
#8755
Posted: 01/28/2009 13:14:28
by David Yee (Standard support level)
Joined: 01/26/2009
Posts: 8

Well, OK...I have successfully (I think) encrypted our test file with the following code (please let me know if I'm missing any vital step..."signing" the file, or setting the trust level of the public key, setting the recipient name or id, whatever!):

SBUtils.Unit.SetLicenseKey("3D4A...950A")

Try
Dim SBBKey As New SBPGPKeys.TElPGPKeyring
Dim SSBPGPWriter As New SBPGP.TElPGPWriter
Dim fsInputFile As FileStream
Dim fsOutputFile As FileStream

fsInputFile = New FileStream(strFileName, FileMode.Open)
fsOutputFile = New FileStream(strFileName & ".gpg", FileMode.Create)

SBBKey.Load("C:\HSATransmit\pubring.gpg", "", True)
SBBKey.FindPublicKeyByEmailAddress("fxrunit@mellon.com", 0)

SSBPGPWriter.Filename = strFileName & ".gpg"
SSBPGPWriter.InputIsText = True
SSBPGPWriter.EncryptingKeys = SBBKey
SSBPGPWriter.Encrypt(fsInputFile, fsOutputFile, 0)

fsInputFile.Close()
fsOutputFile.Close()

Return True
Catch ex As Exception
MessageBox.Show("Encryption error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End Try
#8758
Posted: 01/29/2009 02:45:30
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 450

Hi.
1) SBBKey.FindPublicKeyByEmailAddress("fxrunit@mellon.com", 0) is a function, that returns PGP key, so it's call in your code does nothing.
2) In your code (SSBPGPWriter.EncryptingKeys = SBBKey ) file will be encrypted to all keys, contained in keyring.
3) to sign data, you should use .EncryptAndSign method(), and load secret key with which you are signing.
#8761
Posted: 01/29/2009 06:13:45
by David Yee (Standard support level)
Joined: 01/26/2009
Posts: 8

Mykola:
Thank you for your reply. I then have a couple more follow up questions:
How do I specify a particular public key on my keyring to use in the encryption? How do I specify the recipient (or is this the same question)?
#8762
Posted: 01/29/2009 06:38:12
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 450

You can create another (empty) keyring, and add to it only the key which you wish to use, and set it to .EncryptingKey property:
Dim encrKeyring As New SBPGPKeys.TElPGPKeyring
encrKeyring.Add(SBBKey.PublicKeys[SBBKey.FindPublicKeyByEmailAddress(...)])

Also you can use property .Enabled of public keys and their subkeys (please refer documentation for the description).
#8764
Posted: 01/30/2009 15:13:25
by David Yee (Standard support level)
Joined: 01/26/2009
Posts: 8

Mykola:
I have just now tried your new keyring suggestion:
'*******************************************************************
Dim SBBKey As New SBPGPKeys.TElPGPKeyring

SBBKey.AddPublicKey(SBBKey.PublicKeys[SBBKey.FindPublicKeyByEmailAddress("fxrunit@mellon.com", 0)])

'*******************************************************************

It works better when I use () instead of []:

'*******************************************************************
SBBKey.AddPublicKey(SBBKey.PublicKeys(SBBKey.FindPublicKeyByEmailAddress("fxrunit@mellon.com", 0)))
'*******************************************************************

Follow up question: How do I specify the recipient, or is it done when I've added the above public key?
Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.

Reply

Statistics

Topic viewed 6180 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!