Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get RSA public key string #20

Closed
yuval-netanel opened this issue Dec 13, 2014 · 8 comments
Closed

Get RSA public key string #20

yuval-netanel opened this issue Dec 13, 2014 · 8 comments

Comments

@yuval-netanel
Copy link

I want to send the public key to the server.
This is how I tried to get the public key string, but it returns null:

 MIHRSAKeyFactory *factory = [[MIHRSAKeyFactory alloc] init];
 factory.preferedKeySize = MIHRSAKey512;
 MIHKeyPair *keyPair = [factory generateKeyPair];

 NSString *publicKeyStr = [keyPair.public description];
 NSLog(@"%@", publicKeyStr);// logs null

 NSData *data = [keyPair.public dataValue];
 publicKeyStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
 NSLog(@"%@", publicKeyStr);// logs null

Any suggestions?

@hohl
Copy link
Owner

hohl commented Dec 13, 2014

Thats quite strange. Your code snippet seems okay. Any functionality of MIHRSAKeyFactory should become automatically tested in MIHRSAKeyFactoryTests, so there shouldn't be any issues with it (since all tests run without problems, tested locally on my machine and on Travis continuos integration server).

I'm sorry, but I guess I can't help you.

@askxlogic
Copy link

@hohl I have same issue. I found that reason of it is wrong encoding of NSData that return method

[keyPair.public dataValue];

I think that this issue and this issue is same.

@hohl
Copy link
Owner

hohl commented Feb 28, 2015

You mean, using NSDataBase64DecodingIgnoreUnknownCharacters fixes this issue?

@askxlogic
Copy link

For fixing this issue change method

- (NSString *)description
{
    return [[NSString alloc] initWithData:[self dataValue] encoding:NSUTF8StringEncoding];
}

to

- (NSString *)description
{
    return [[self dataValue] base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
}

in MIHRSAPublicKey.m

@askxlogic
Copy link

I am sorry. It just looks like similar bugs. Everything working for me without NSDataBase64DecodingIgnoreUnknownCharacters

@hohl
Copy link
Owner

hohl commented Feb 28, 2015

description is for debugging anyway. However I thought this issue is about not being able to generate public keys? If it's about the description output I may need to have second look at it.

@yuval-netanel
Copy link
Author

Sorry if it wasn't clear, but it's about the description output.

@hohl
Copy link
Owner

hohl commented Mar 1, 2015

Oh dear. Since the description field has been added for testing purposes I've forgotten about the unit tests for, I'm sorry.

I'll fix it immeditley, this should do the job:

- (NSString *)description
{
    return [[self dataValue] MIH_base64EncodedString];
}

@hohl hohl closed this as completed in e5ec04f Mar 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants