EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Extract Base64 NSString from TElPGPPublicKey

Posted: 08/27/2014 00:49:46
by Eduard Mossinkoff (Basic support level)
Joined: 08/22/2014
Posts: 1


At the moment I'm using the OpenPGP SBB trial version in a iOS App. I can create a key pair and save it do file. But I need so send the public key in Base64 encoding to another party and I can't seem to find the correct way to perform that task. I tried writing the public key to a stream (by the way why aren't the TStream classes documented?) and then try to write the stream to a buffer which can then be used to create a NSData instance. The iOS OpenPGP sample code does not show me how to do this so a little example would be helpful. Thank you.

Posted: 08/27/2014 01:38:54
by Eugene Mayevski (Team)

When writing the key, use Armoring (set Armor parameter of the Save* method to true). This will produce the output in standard text format (i.e. in format that another OpenPGP-compatible application can load).

As for documentation - unfortunately it lags behind.

Sincerely yours
Eugene Mayevski
Posted: 08/27/2014 03:15:51
by Polina Khorolets (Basic support level)
Joined: 12/02/2013
Posts: 6


you could do the task like this:

TElPGPPublicKey *publicKey = keyring->get_PublicKeys(0);
std::string fn = "somefilename";
publicKey->SaveToFile(fn, true);
NSData *data = [NSData dataWithContentsOfFile:[NSString stringWithUTF8String:fn.c_str()]];
NSString *base64String = [data base64EncodedStringWithOptions:0];
NSLog(@"%@", base64String);

and with stream:

TMemoryStream *stream = new TMemoryStream();
publicKey->SaveToStream(stream, true);
int InSize = (int)stream->get_Size();
char InBuffer[InSize];
stream->Read(InBuffer, InSize);
NSData *data = [NSData dataWithBytes:InBuffer length:InSize];
NSString *base64String = [data base64EncodedStringWithOptions:0];
NSLog(@"%@", base64String);



Topic viewed 526 times

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


Back to top

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

Got it!