hohl / MIHCrypto

OpenSSL wrapper for Objective-C [cryptography]
MIT License
341 stars 68 forks source link

Share and use public and private key #55

Closed maxisme closed 6 years ago

maxisme commented 6 years ago

How could I go about sharing and then using a generated public key?

I have wrote the functions:

-(NSString*)keyTo64String:(id)key{
    NSData *key_data = [NSKeyedArchiver archivedDataWithRootObject:key];
    return [key_data base64EncodedStringWithOptions:0];
}

-(id)string64ToKey:(NSString*)key{
    NSData* priv_actual_data = [[NSData alloc] initWithBase64EncodedString:key options:0];
    return [NSKeyedUnarchiver unarchiveObjectWithData:priv_actual_data];
}

The first function will return a string representation of the MIHPublicKey or MIHPrivateKey object. And the second from the string to the object.

It would be cool if I could export the key in a format similar to a .pem file. It would also be great if I could read that format and turn it back into the object.

How would you recommend doing it?

maxisme commented 6 years ago

I have noticed the dataValue but what about being able to set this?

hohl commented 6 years ago

All keys (symmetric and asymmetric) have a constructor - initWithData:dataValueand a getter dataValue which work with the raw key values. PEM is just the raw values BASE64 encoded. Have a look at the unit tests in MIHRSAKeyTests.m for sample usage with PEM files.

maxisme commented 6 years ago

Awesome thank you.

Have you thought about implementing Elliptic Curve technology?

hohl commented 6 years ago

Yes, ECC was on my TODO list. But since I never needed it I also never done so.