Comments (4)
Can you please send me what is contained in „encryptionError“?
Am 25.06.2014 um 16:39 schrieb Hugo Doria [email protected]:
I need to encrypt a NSString using a public from a webserver certificate on iOS and your library will be very useful, but I am having some problems.
Here's what i am doing:
NSString *publicKey = @"Public Key From My WebServer Certificate";
NSData *data = [[NSData alloc] initWithBase64EncodedString:publicKey options:NSDataBase64DecodingIgnoreUnknownCharacters];id symmetricKey = [[MIHRSAPublicKey alloc] initWithData:data];
NSError encryptionError = nil;
NSData *messageData = [@"My Password" dataUsingEncoding:NSUTF8StringEncoding];
NSData *encryptedData = [symmetricKey encrypt:messageData error:&encryptionError];
NSString newStr = [[NSString alloc] initWithData:encryptedData encoding:NSUTF8StringEncoding];
newStr is always null. What I am doing wrong?—
Reply to this email directly or view it on GitHub.
from mihcrypto.
encryptionError is null.
NSString *publicKey = @"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuFyIytvyIXxSMqjJ+swm3xmc0lulL6FnpIRXorYnJ4Trl/6GJZz2Q26RwFxVtBIOEURfpTeaX2dnnmQEdD9f5oYFCLMy1EMSaalUztaQOHTxvCDnOLKcqDhuygzmsdbrmGoAUJtWBHPPBad9EIB+zVW7NWPcwfchbZoir84UwOr4WhMH+c3wRHyo1ZCgcSG9dpF4NBZZJ5XJ0A0MzitF+GCN5idfryYR8b+X7pQ/spaIUGhyDkz9evdMKjbyZsoWJ/5RG5BONnhraf8gY9hmfA6VZuISbz6gkuRVjeYRO7sa8xAXlUhfkth+8ewJ4TjxkKbazxcnc0OJt72+fyn4+wIDAQAB"; // Base64 encoded key
NSData *publicKeyData = [[NSData alloc] initWithBase64EncodedString:publicKey options:NSDataBase64DecodingIgnoreUnknownCharacters];
id<MIHPublicKey> symmetricKey = [[MIHRSAPublicKey alloc] initWithData:publicKeyData];
NSError *encryptionError = nil;
NSData *passwordData = [@"password" dataUsingEncoding:NSASCIIStringEncoding];
NSData *encryptedData = [symmetricKey encrypt:passwordData error:&encryptionError];
NSLog(@"Public Key Data: %@", publicKeyData);
NSLog(@"Password Data: %@", passwordData);
NSLog(@"Encrypted Data: %@", encryptedData);
NSLog(@"Encryption Error: %@", encryptionError);
Logs:
Public Key Data: <30820122 300d0609 2a864886 f70d0101 01050003 82010f00 3082010a 02820101 00b85c88 cadbf221 7c5232a8 c9facc26 df199cd2 5ba52fa1 67a48457 a2b62727 84eb97fe 86259cf6 436e91c0 5c55b412 0e11445f a5379a5f 67679e64 04743f5f e6860508 b332d443 1269a954 ced69038 74f1bc20 e738b29c a8386eca 0ce6b1d6 eb986a00 509b5604 73cf05a7 7d10807e cd55bb35 63dcc1f7 216d9a22 afce14c0 eaf85a13 07f9cdf0 447ca8d5 90a07121 bd769178 34165927 95c9d00d 0cce2b45 f8608de6 275faf26 11f1bf97 ee943fb2 96885068 720e4cfd 7af74c2a 36f266ca 1627fe51 1b904e36 786b69ff 2063d866 7c0e9566 e2126f3e a092e455 8de6113b bb1af310 1795485f 92d87ef1 ec09e138 f190a6da cf172773 4389b7bd be7f29f8 fb020301 0001>
Password Data: <70617373 776f7264>
Encrypted Data: <51ea4ab2 8b34a6cf 3c09f109 0cfa5e33 ded2f388 ff240889 47f54cd4 64a4621a 0787c985 ab1705f9 d8b9b4ed d893a3fe 0c019c28 9f389380 ca6fa613 090fa1ed cfb6f393 3395ced1 afae556e 41de765f 19bdb5d2 1be0ae50 ddabcfaf afd517cc dc7faf12 69bcc4ac b4ac8b2b 3b32e610 e684489f e14af7ae 1cbaabe6 a92cfff8 a5b0ec67 5a479e69 55b6cf81 2834089c 192e097b dc352c86 21b256ee e5a13353 129d3808 86c78902 361bb98a c9618a80 cbcafc85 117cd8ef ace60b84 6ca6cfb3 b9beeee3 8f083d6a a26ba700 3cc684b8 16791159 50b0bc1b 605e96b4 ca5cb0ff 5dff656a ca56774f 4f614d2b 5d31135c 1c605c10 e96a0456 66431bf9 d6f65c39>
Encryption Error: (null)
from mihcrypto.
As you can see encryptedData
does contain some value. But what you try to do is to convert the binary data to a string. But that won't work since encryptedData
isn't a string! BASE64 is a way to represent binary data inside a string.
Try:
NSString* newStr = [encryptedData base64EncodedStringWithOptions:0]; // iOS 7+, by iOS Core API
But this API is introduced by Apple in iOS7. If you want to target older versions of iOS there is some alternative method in MIHCrypto/NSData+MIHConversion.h
, which does exactly the same:
NSString* newStr = [encryptedData MIH_base64EncodedStringWithWrapWidth:64]; // iOS 5+, by MIHCrypto helpers
from mihcrypto.
Thank you. Worked fine. :)
from mihcrypto.
Related Issues (20)
- Carthage support HOT 2
- CocoaPods with use_frameworks! option HOT 4
- Can't compile any app HOT 4
- Digital Singned PKCS8 format
- Exception initializing MIHRSAPrivateKey with NSData
- RSA encryption using local certificate producing OpenSSL error HOT 1
- Supporting ECB mode for AES Encryption HOT 2
- Any plan to support OSX 10.11? HOT 2
- RSA key generation seed? HOT 2
- Pod install error HOT 1
- transitive dependency error while working with cocoapods HOT 1
- can i create a self-signed certificate? HOT 1
- How do I initialize MIHRSAPublicKey using the public key string returned by the server? HOT 2
- 'openssl/evp.h' file not found HOT 8
- Share and use public and private key HOT 4
- Current status of repository? HOT 2
- 0.5.0 can not find in the pod repo HOT 1
- memory leak found in MIHRSAPrivateKey HOT 7
- cannot find the newest version(0.5.0) in pod HOT 2
- Use ECC encryption to decrypt how to use. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mihcrypto.