JohnLemon
JohnLemon

Reputation: 157

Display encrypted image on UIIImageView in objective c

I encrypted an image (png) by using AES (Encryption algorithm) and get encrypted NSData. I use FBEncryptor framework. Now I am trying to display it on UIImageView, but it does't work. Here is my code:

@interface ImageEncryptingViewController ()

@property (strong, nonatomic) IBOutlet UIImageView *encoptdImg;


@end

@implementation ImageEncryptingViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    UIImage *img = [UIImage imageNamed:@"image.png"];

    NSData *imageData = UIImagePNGRepresentation(img);

    NSData* encryptedData = [FBEncryptorAES encryptData:imageData key:imageData iv:imageData];

    UIImage *image = [[UIImage alloc]initWithData:encryptedData];

    NSLog(@"%@", encryptedData);

    _encoptdImg.image = image;



}

In the end I want to get encrypted image, where we can see noise or something else, but not original image. For example this website do it. I need it on ios by using AES encryption algorithm. How I can solve this problem? Any ideas? Thanks.

Upvotes: 1

Views: 525

Answers (2)

Amin Negm-Awad
Amin Negm-Awad

Reputation: 16660

The problem in this question is that you encrypt the whole image file instead of the bitmap solely. The file contains meta information that is needed to display the image. I. e. the file has a signature at its beginning to mark it as PNG. Encrypting the file, you destroy that signature.

You have to encrypt solely the bitmap.

This leads to the next question, how to get the pure bitmap data out of an image. Fortunately this question is answered on stack overflow several times, i. e. here.

Upvotes: 1

Mortgy
Mortgy

Reputation: 563

lunapic.com is using a placeholder image you can just put such image as a placeholder for an encrypted image, an encrypted image will not have any image attributes in order to get UIImageView to read it, when user decrypt the image, then you can just place the decrypted image in that placeholder, that's it

Upvotes: 0

Related Questions