EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Extract Base64 NSString from TElPGPPublicKey

Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.
#30495
Posted: 08/27/2014 00:49:46
by Eduard Mossinkoff (Basic support level)
Joined: 08/22/2014
Posts: 1

Hello,

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.

Brgds,
Eduard
#30497
Posted: 08/27/2014 01:38:54
by Eugene Mayevski (EldoS Corp.)

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
#30498
Posted: 08/27/2014 03:15:51
by Polina Khorolets (Basic support level)
Joined: 12/02/2013
Posts: 6

Hello

you could do the task like this:

Code
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:

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

Reply

Statistics

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