EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Using the ElPGPWriterX.Encrypt in VB6

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.
#11229
Posted: 10/02/2009 13:00:48
by Marc-Andre Poulin (Basic support level)
Joined: 10/02/2009
Posts: 2

I trying to encode a string in memory in Visual Basic 6. I've done it fine with a file using EncryptFile but I trying to make it work with the Encrypt but it using a Stream. In VB6 the parameters are IUnknown, is there's a sample that show how to use this in VB6 or any other solution to encrypt a String.

Thanks
#11239
Posted: 10/06/2009 05:16:19
by Ken Ivanov (EldoS Corp.)

Thank you for your interest in our products.

Sorry, there is no such sample available. ElPGPWriterX expects objects passed to the Encrypt() method to implement the standard OLE IStream interface. The easiest way to encrypt a string and bypass dealing with files is to find some existing COM component that supports string <-> IStream mapping. Another option is to implement such component manually.
#11249
Posted: 10/06/2009 09:04:10
by Marc-Andre Poulin (Basic support level)
Joined: 10/02/2009
Posts: 2

I better option would be to provide more function definition in the ActiveX to be easily usable in VB6, Access and other VBA tools with function like EncryptString and EncryptByteArray that would take String and Byte().

Maybe an easier solution, adding functions in the UtilsX that take a String or Byte() and return a Stream so we could do the stream thing directly like this

Dim strEncode As String, util As New ElPGPUtilsX, stream As IUnknown
strEncode = "my string to encode"
stream = util.StringToStream(strEncode)


Don't know if it's usable, but having to Implements IStream in VB is not an easy thing to do and I don't have the time to try to figure how to make it workable.

Thanks
#11250
Posted: 10/06/2009 09:18:34
by Eugene Mayevski (EldoS Corp.)

We do have an in-memory implementation of IStream in our ToDo list, but this was not made due to low popularity of such usage scenario.


Sincerely yours
Eugene Mayevski
#12020
Posted: 12/31/2009 04:46:08
by Christian Paucksch (Standard support level)
Joined: 12/31/2009
Posts: 4

Hello,

we program with the VC++ 6. The methods of EldoS ActiveX often need as parameter objects, which implement the interface IStream. A simple test of an OLE-provided implementation of the IStream interface failed.

Code
// Creating IElPGPPublicKeyX instance1.
PGPBBox7::IElPGPPublicKeyX* pPGPPublicKeyInstance1 = NULL;
hr = CoCreateInstance(CLSID_ElPGPPublicKeyX, NULL, CLSCTX_INPROC_SERVER, IID_IElPGPPublicKeyX,
(void**)&pPGPPublicKeyInstance1);
if (FAILED(hr))
  throw OurException("Failed to create pPGPPublicKeyInstance1");


BSTR pgpPublicKeyFilename = SysAllocString(L"my_publicKey.asc");
hr = pPGPPublicKeyInstance1->LoadFromFile(pgpPublicKeyFilename);
if (FAILED(hr))
  throw OurException("Failed to load from file with error " + ::GetLastError());


// Creating IStream implementation object.
unsigned long iSize = 100000;
HGLOBAL   hMem = ::GlobalAlloc(GMEM_MOVEABLE,iSize);
if (!hMem)
  AfxThrowMemoryException();
CComPtr<IStream> pStream;
hr = ::CreateStreamOnHGlobal(hMem,FALSE,&pStream);
if (FAILED(hr))
  throw OurException("Failed to create IStream object");

// Save data to stream.
//the key will be armored into base64 representation before saving.
VARIANT_BOOL armor = -1;
pPGPPublicKeyInstance1->SaveToStream(pStream, armor);
pPGPPublicKeyInstance1->Release();


// Creating IElPGPPublicKeyX instance2.
PGPBBox7::IElPGPPublicKeyX* pPGPPublicKeyInstance2 = NULL;
hr = CoCreateInstance(CLSID_ElPGPPublicKeyX, NULL, CLSCTX_INPROC_SERVER, IID_IElPGPPublicKeyX,
(void**)&pPGPPublicKeyInstance2);
if (FAILED(hr))
  throw OurException("Failed to create pPGPPublicKeyInstance2");

// set the seek position to the beginning of the stream.
LARGE_INTEGER liBeggining = { 0 };
pStream->Seek(liBeggining,STREAM_SEEK_SET, NULL);

// Load data from stream.
pPGPPublicKeyInstance2->LoadFromStream(pStream);
pPGPPublicKeyInstance2->Release();


We get an error:
Quote
unhandled exception in OurTest.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception.

at line
Code
pPGPPublicKeyInstance2->LoadFromStream(pStream);


Is this object for this purpose unsuitable? Can you recommend an implementation to us?

Christian
#12023
Posted: 01/03/2010 03:29:23
by Ken Ivanov (EldoS Corp.)

Thank you for contacting us.

The below code
Code
unsigned long iSize = 100000;
HGLOBAL   hMem = ::GlobalAlloc(GMEM_MOVEABLE,iSize);
if (!hMem)
  AfxThrowMemoryException();
CComPtr<IStream> pStream;
hr = ::CreateStreamOnHGlobal(hMem,FALSE,&pStream);

creates an IStream with size of 100000 bytes. After saving the key to such object the stream consists of N bytes of key material immediately followed by uninitialized data of (100000 - N) bytes. This results in failure to load a key, as stream content does not form a valid key material.

A correct way would be to re-size the stream right after saving the key to it and prior to loading it into another key object in the following way:
Code
   LARGE_INTEGER liPos = { 0 };
   ULARGE_INTEGER uliPos;
   hr = pStream->Seek(liPos, STREAM_SEEK_CUR, &uliPos);
   if (FAILED(hr))
   {
      // ...
   }
   pStream->SetSize(uliPos);
#12032
Posted: 01/04/2010 04:24:28
by Christian Paucksch (Standard support level)
Joined: 12/31/2009
Posts: 4

Thanks, it works.

Christian.
Also by EldoS: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.

Reply

Statistics

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