开发者

Encrypting different types of files using C or Objective-C

开发者 https://www.devze.com 2023-03-04 04:53 出处:网络
I have chosen an algorithm to encrypt a file. i may encrypt text or image files. How can I write a generic type of encryption method that works with both te开发者_开发技巧xt and image files? I\'m work

I have chosen an algorithm to encrypt a file. i may encrypt text or image files. How can I write a generic type of encryption method that works with both te开发者_开发技巧xt and image files? I'm working with Objective-C.


What ever you are encrypting you might be using the data or specifically NSData, then converting it to char array and then applying the algorithm. So make a method that takes NSData as an argument, and return encrypted NSData.

e.g.

-(NSData*)encrypt:(NSData*)data{
  ///your algorithm

  return enCryptedData;
}

Convert your Image or File into NSData and pass it to the method.


Write an encryption method that operates on a stream/sequence/etc. of bytes (char). Then read in the text file or the image file as bytes (i.e. don't try to apply any sort of encoding to the contexts of the text file to turn it into Unicode) and do the encryption.

0

精彩评论

暂无评论...
验证码 换一张
取 消