EldoS | Feel safer!

Software components for data protection, secure storage and transfer

TElPGPPublicKey.SaveToStream broken?

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.
Posted: 07/30/2008 14:06:41
by Orri Eiriksson (Basic support level)
Joined: 07/23/2008
Posts: 9

Hi all,

I'm having the hardest time getting SaveToStream from ElPGPPublicKey to work properly. SaveToFile works as I expected it to, but the stream equivalent always seems to do nothing.

The result of this code:
TElPGPPublicKey tempPubKey = keyring.get_PublicKeys(index);

MemoryStream ms = new MemoryStream();
tempPubKey.SaveToStream(ms, true);
tempPubKey.SaveToFile(tempfile, true);

StreamReader reader = new StreamReader(ms);
String keyStr = reader.ReadToEnd();

Always seems to be an empty keyStr, but has the key correctly saved to tempfile.

No example covers this, and I couldn't find any other discussions on this.

Any ideas how I can retrieve the key as a string, without reading the file I just wrote?


Posted: 07/30/2008 14:17:47
by Eugene Mayevski (EldoS Corp.)

Never use StreamReader class with SecureBlackbox. It's buggy.

Sincerely yours
Eugene Mayevski
Posted: 07/30/2008 14:36:57
by Orri Eiriksson (Basic support level)
Joined: 07/23/2008
Posts: 9

I'm afraid I don't know of any other ways to read the contents of a stream to a string. Does SecureBlackBox come with any utility to convert a public/private key to string?
Posted: 07/30/2008 14:43:00
by Orri Eiriksson (Basic support level)
Joined: 07/23/2008
Posts: 9

Never mind! I discovered that the problem was that I had to reset the MemoryStream's pointer to the beginning of the stream before reading it with StreamReader! Oops!

For the curious, what I was missing was a call to

ms.Seek(0, SeekOrigin.Begin);

Before creating the StreamReader.



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