Implementation of Objective-c string MD5, SHA1, SHA256, AES encryption

Source: Internet
Author: User
Tags base64 md5 encryption sha1 sha1 encryption asymmetric encryption

Problem:

When I do user login, the background API needs to MD5 the encryption of the number and request time of the merged strings, so on the GitHub to find an encrypted frame, link: https://github. (ox) Com/paulery2014/cocoasecurity, I wrote a small demo myself to make it easy for everyone to use.


How to use:

Download the cocoasecurity framework to the local, import the Base64 and cocoasecurity 4 files, and then in the need to call the. m file import "CocoaSecurity.h" header file


Various ways to encrypt the source code:

    
    Signature Algorithm (MD5, SHA1, HMAC)//String MD5 encryption Cocoasecurityresult *result_md5 = [cocoasecurity md5:@] Liuxiaofei
    _md5 "];
    String SHA1 encryption Cocoasecurityresult *RESULT_SHA1 = [cocoasecurity sha1:@ "LIUXIAOFEI_SHA1"];
    
    String SHA256 encryption Cocoasecurityresult *result_sha256 = [cocoasecurity sha256:@ "liuxiaofei_sha256"];
    Print hash (md5,sha1,sha256) after the encryption of the character difference NSLog (@ "MD5 encrypted string is hex:%@", Result_md5.hex);
    NSLog (@ "MD5 encrypted string is hexlower:%@", result_md5.hexlower);
    
    NSLog (@ "MD5 encrypted string is base64:%@", result_md5.base64);
    NSLog (@ "SHA1 encrypted string is hex:%@", Result_sha1.hex);
    NSLog (@ "SHA1 encrypted string is hexlower:%@", result_sha1.hexlower);
    
    NSLog (@ "SHA1 encrypted string is base64:%@", result_sha1.base64);
    NSLog (@ "SHA256 encrypted string is hex:%@", Result_sha256.hex);
    NSLog (@ "SHA256 encrypted string is hexlower:%@", result_sha256.hexlower);

    NSLog (@ "SHA256 encrypted string is base64:%@", result_sha256.base64); Symmetric encryption Algorithm (3DS, AES)/*AES encryption: * Advanced Encryption Standard * is the next generation of encryption algorithm standard, fast, security level high *aes  standard one implementation is  
    rijndael  algorithm */Cocoasecurityresult *result_aes = [cocoasecurity aesencrypt:@ "Liuxiaofei" key:@ "TestKey"];
    NSLog (@ "AES encrypted string:%@", Result_aes.hex);
    NSLog (@ "AES encrypted string:%@", result_aes.hexlower);
    
    NSLog (@ "AES encrypted string:%@", result_aes.base64);
 Asymmetric Encryption Algorithm (data volume comparison hours)//Rsa....blablabla

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.