Closed btnguyen2k closed 9 years ago
Hi, it doesn't work. The function should be:
+ (NSString *)decryptString:(NSString *)enc privateKey:(NSString *)pubKey;
It should decrypt the result returned by
+ (NSString *)encryptString:(NSString *)str publicKey:(NSString *)pubKey;
@ideawu, I assume the following flow:
Either case, the iOS app only has the public key to encrypt and decrypt. Hence, my decrypt function is "decryptWithPublicKey"
Test with this string, it should work: PUBLIC_KEY = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJh+/sdLdlVVcM5V5/j/RbwM8SL++Sc3dMqMK1nP73XYKhvO63bxPkWwaY0kwcUU40+QducwjueVOzcPFvHf+fECAwEAAQ=="; PRIVATE_KEY = "MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAmH7+x0t2VVVwzlXn+P9FvAzxIv75Jzd0yowrWc/vddgqG87rdvE+RbBpjSTBxRTjT5B25zCO55U7Nw8W8d/58QIDAQABAkBCNqIZlsKCut6IOPTIQM7eoB/zuhIk3QdxCvunu4mV+OIv00b6lN02ZsQ64nblu6dP9UuhlyclFaGlXtwqfkABAiEA0XQlb0mT5cZ8VpNNOqojeWoyrvQIRPGhdBrq3VroT4ECIQC6YoVd0yaT6lUDV+tgKtNbQN8m9hVIMgE/awRT/aXicQIhAK+jIbEMlgTcSG+g3eYPveeWciHbaQPHS4g8+i3ciWoBAiBddJsEwaQ9VKlN5N67uJ2DyxJZediP+6rOfr2L08pCsQIhAJLmeidBF0uJxNZiBgnkIHlRQ167qE1D0s5SQ2j5217G";
Encrypted String: "NpdBZEm3AasQO/AvFD/ss8HehniOy3nS5b85MwOexZTRoKqQbK+Nu5tWjr+ZIynaC5ij+XJ8+iqNoIpzHVQ/+A==" Decrypt that string should return "This is a test"
Edit: I am working on 2 more functions:
Good! I will wait for the other 2 functions.
So we need:
+ (NSData *)encryptData:(NSData *)data privateKey:(NSString *)privKey;
+ (NSData *)decryptData:(NSData *)data publicKey:(NSString *)pubKey;
+ (NSData *)decryptData:(NSData *)data privateKey:(NSString *)privKey;
And must use TAB to indent.
Implement decryption function.