How to encrypt strings, images, and videos in IOS

Source: Internet
Author: User

How to encrypt strings, images, and videos in IOS

1,Decodes a string using gtmbase64 Encoding

Gtmdefines. hgtmbase64.hgtmbase64. m

You can find these three files here (gtmdefines. H is on the second page, click Next in the upper right corner to jump to the second page)

Http://code.google.com/p/google-toolbox-for-mac/source/browse/trunk/Foundation? R = 87

2. codec functions (you can change the codec string, image, and video to the corresponding filepath ):

Read the file from the drivers path of the simulator and the real machine, encode it, and write it into the file. Read it and decode it.

// Encryption function

-(Void) func_encodefile

{

// Nsstring * Path = [nshomedirectory () stringbyappendingformat: @ "/documents/test.png"];

Nsstring * filepath = [nshomedirectory () stringbyappendingformat: @ "/documents/iphone4.mov"];

// Convert the file path to nsdata

Nsdata * imagedataorigin = [nsdata datawithcontentsoffile: filepath];

// Exception or handling of the first 1000 bits

Unsigned char * cbyte = (unsigned char *) [imagedataorigin bytes];

For (INT Index = 0; (index <[imagedataorigin length]) & (index <1000); index ++,
Cbyte ++)

{

* Cbyte = (* cbyte) ^ arrayforencode [Index];

}

// Base64 encoding nsdata

Nsdata * imagedataencode = [gtmbase64 encodedata: imagedataorigin];

[Imagedataencode writetofile: filepath atomically: Yes];

}

// Decryption Function

-(Void) func_decodefile

{

// Nsstring * filepath = [nshomedirectory () stringbyappendingformat: @ "/documents/test.png"];

Nsstring * filepath = [nshomedirectory () stringbyappendingformat: @ "/documents/iphone4.mov"];

// Read the data corresponding to the encrypted file

Nsdata * dataencoded = [nsdata datawithcontentsoffile: filepath];

// Base64 decoding nsdata

Nsdata * datadecode = [gtmbase64 decodedata: dataencoded];

// Exception or handling of the first 1000 bits

Unsigned char * cbyte = (unsigned char *) [datadecode bytes];

For (INT Index = 0; (index <[datadecode length]) & (index <10); index ++, cbyte ++)

{

* Cbyte = (* cbyte) ^ arrayforencode [Index];

}

[Datadecode writetofile: filepath atomically: Yes];

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.